2
votes

Am 100% new to JMS and Camel

This is the Scenario

I have a Spring Web application, a JMS (ActiveMQ), Camel

The web application needs to send information to JSM, through camel in an asynchronous manner. i.e. After sending information to Camel, the website should not wait for the response. The web page should continue.

And , my application should listen to the queue for any response in the Queue. Once , any response is received, a specific bean has to be invoked.

Is this possible???

This is the configuration in my client

Camel Context :

<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
  <!-- END SNIPPET: e1 -->

  <!-- START SNIPPET: e2 -->
  <camel:camelContext id="camel-client">
    <camel:template id="camelTemplate"/>
  </camel:camelContext>
  <!-- END SNIPPET: e2 -->

  <!-- START SNIPPET: e3 -->
  <!-- Camel JMSProducer to be able to send messages to a remote Active MQ server -->
  <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61610"/>
  </bean>
  <!-- END SNIPPET: e3 -->

</beans>

Camel Code :

ApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

// get the camel template for Spring template style sending of messages (= producer)
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

System.out.println("Invoking the multiply with 22");
// as opposed to the CamelClientRemoting example we need to define the service URI in this java code
int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
System.out.println("... the result is: " + response);

This is working good. But the prblem is , this is synchronous.

I want this to be asynchronous.

How to do it

2
In that case , how is it possible? Updating my questionmadhairsilence

2 Answers

0
votes

You won't need to do all that stuff in the Camel Remoting example (which I suspect you have started out with).

So, you want to stage some processing through a queue. Just so that I don't misinterpret this:

Web Request -> JMS queue -> Camel -> Bean -> Done

Create a route:

<camel:camelContext id="camel-client">
   <camel:template id="camelTemplate"/>
   <camel:route>
      <camel:from uri="jms:queue:myQueue"/>
      <camel:bean ref="someBean"/>
    </camel:route>
</camel:camelContext>

Then in your code, just fire of the message: camelTemplate.asyncSendBody("jms:queue:myQueue", ExchangePattern.InOnly, someData);

0
votes

The answer is a simple

int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);

This should be

int response = (Integer)camelTemplate.sendBody("jms:queue:numbers",22);

Just dont mention the ExchangePattern and you are done.

Moral : Please do read documentation properly .