user2985281
user2985281

Reputation: 3

asyncSend to camel direct entpoint

I want to know what happen to message when a producer send asynchronous to camel direct endpoint and then from this direct endpoint to bean Mybean which use @RecipientList annotation on its method :

producerTemplate.asyncSendboby("direct:MybeanA", message);

then:

from(direct:MybeanA).bean(MyBeanA);

Mybean class:

class MybeanA {

@RecipientList
 public String doSomething(Exchange exchange){

    // check the exchange and return a endpoint URI
    setDestId()

  return endpoitUri; // this URI is like "activemq:destination-" + getDestId() + "?maxConcurrentConsumers=10&consumer.prefetchSize=1"
 }

So messages witch are produced asynchronously, MybeanA will treat them one by one , and when they reach activemq endpoint will be consumed in separate thread ??? Is that a good approach to send asynchronously to direct in that case ??

Upvotes: 0

Views: 1358

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

producerTemplate.asyncSendboby("direct:MybeanA", message);

Just means it will not block the calling thread of this method, but it doesn't means the message is processed asynchronously. We need to check the camel route for it.

If the camel route can process the message asynchronously, the message is processed asynchronously even you use ProducerTemplate.Sendbody() method to send the message.

As most camel components are support the asynchronous Processing API, camel will try to use that API by default, but if the component or the processor just has the sync processing API, camel route will switch the sync model when calling the sync processing API.

The camel route you just showed has the asynchronous processing API, so the message is processed asynchronously.

When you routing the message to activemq endpoint, we need to check the route which has the actviemq endpoint to make sure it is processed asynchronously.

Upvotes: 0

Related Questions