2
votes

Can someone please help me understand the difference between async scope and vm in mule. I understand vm is like in memory JMS, but if my requirement is to process something asynchronously, can I use either of them at will ? If not, what are the differences.

For example, what can be the difference between the following:

Main flow1 calling another flow using async scope:

<flow name="mainflow1">
...
<async>
  <flow-ref name="anotherflow" /> 
</async>
...
</flow>

Main flow2 calling another flow using VM:

<flow name="mainflow2">
...
<outbound-endpoint address="vm://anotherflow" exchange-pattern="one-way" />
..
</flow>

Assume another flow writes a record to some database and is not of request-response type.And how about thread safety. Are both complete thread safe?

2

2 Answers

4
votes

Matt's answer is correct. I might add a couple of additional benefits you get for the extra cost of going through a queue instead of just calling another flow:

  1. Using a VM outbound endpoint (or indeed, any queue) offers you the ability to queue up messages under temporary high load, and control what happens when there are more messages than your target flow can consume (maximum outstanding messages, what to do when you reach that maximum, how long to wait for a publish to succeed before you error out, etc). This is the purpose of SEDA.

  2. On the consumer end, using a queue instead of a flow reference allows you to use a transaction to be sure that you do not consume the message unless your intended processing succeeds.

  3. VM queues offer a convenient place to test parts of your application in isolation. You can use the MuleClient in a functional test to send or receive messages from a VM queue to make sure your flows work properly.

3
votes

The main difference between the two is the context of the flow. When using a vm endpoint, mule treats the message as if it were a completely new incoming message. It has a completely new context and separate properties and variables. If you want to inherit the properties and variables from the calling flow, you can use a flow-ref to call a flow or subflow (see here for the differences between a flow and subflow: http://www.mulesoft.org/documentation/display/current/Flows+and+Subflows). Since the vm endpoint creates a new context, there is more overhead in the call and it is less efficient, but with that extra overhead, you get all of the infrastructure that comes with making a full mule call.