Showing posts with label activemq jndi.. Show all posts
Showing posts with label activemq jndi.. Show all posts

Friday, October 12, 2012

ActiveMQ Composite Destinations


ActiveMQ Composite Destinations

Composite queue allows one-to-many relationship. Send a message to One Queue (A) and it will forward the message to Queue B, Queue C and Topic D.
To map Composite destination you need to add following section in virtualDestinations tag.
 <destinationInterceptors>
    <virtualDestinationInterceptor>
        <virtualDestinations>
<compositeQueue name="TEST.QUEUE.A">
   <forwardTo>
<queue physicalName="TEST.QUEUE.B" />
<queue physicalName="TEST.QUEUE.C" />
<queue physicalName="TEST.TOPIC.D" />
   </forwardTo>
</compositeQueue>
        </virtualDestinations>
    </virtualDestinationInterceptor>
  </destinationInterceptors>

By default, subscribers cannot consume messages directly from a composite queue or topic - it is a logical construct only. Given the configuration above, subscribers can only consume messages from TEST.QUEUE.B, TEST.QUEUE.C and TEST.TOPIC.D; but NOT TEST.QUEUE.A.

Using filtered destinations

You may wish to create a virtual destination which forwards messages to multiple destinations but applying a selector first to decide if the message really does have to go to a particular destination.
 <destinationInterceptors>
    <virtualDestinationInterceptor>
        <virtualDestinations>
<compositeQueue name="TEST.QUEUE.A">
   <forwardTo>
<filteredDestination selector="criteria = ‘B’” queue="TEST.QUEUE.B" />
<filteredDestination selector="criteria = ‘C’” queue="TEST.QUEUE.C" />
<filteredDestination selector="criteria = ‘D’” queue="TEST.TOPIC.D" />
   </forwardTo>
</compositeQueue>
        </virtualDestinations>
    </virtualDestinationInterceptor>
  </destinationInterceptors>

In the case above, message from TEST.QUEUE.A will be forwarded to filtered destinations with selector criteria. Result is same as having selector based consumer on TEST.QUEUE.B


Important Aspects of Composite Destinations:

-          Listener Queues (under forwardTo Tag) will not be created automatically. If queues are not present, message will be LOST.
-          If you want to store message in composite queue, make forwardOnly flag as ‘false’. It’s true by default.
<compositeQueue name="TEST.QUEUE.A" forwardOnly="false">   
      <forwardTo>
<queue physicalName="TEST.QUEUE.B" />
   </forwardTo>
</compositeQueue>

-          Composite queue can send the message to Virtual Topic, which will be further consumed by multiple Virtual Destinations.
-          Virtual Topic Selector Aware Consumers will not pull the message if consumer is not active; On the contrary, Filtered Composite destinations pull the message despite of consumer’s active status. This is very helpful in real world scenarios.
-          Important: Composite Destinations Supports wildcards. This is also valid for Filtered Destinations.
<destinationInterceptors>
   <virtualDestinationInterceptor>
      <virtualDestinations>
<compositeQueue name="TEST.QUEUE.A">
<forwardTo>
   <filteredDestination selector="criteria = ‘B’” queue="TEST.B.>."/>
   <queue physicalName="COMPOSITE.WILD.>."/>
</forwardTo>
</compositeQueue>
</virtualDestinations>
</virtualDestinationInterceptor>
</destinationInterceptors>

In the settings above, message will be forwarded to all the queues starting with “COMPOSITE.WILD”. Also, the message with filtered destinations will be forwarded to all the queues starting with ‘TEST.B’.

Thursday, August 30, 2012

WTX with ActiveMQ Using JMS Adapter


WebSphere Transformation Extender's interaction with Activemq. Not hard but little tricks are important. As usual, if you google this solution, you will not find a single site or blog stating exact steps. So, here it is. Post your comments for questions.

Step 1: Setting jndi.propertise

Place provided “jndi.properties” file in <WTX_INSTALL>/java/lib directory or defined CLASSPATH. Sample jndi.properties can be downloaded from here.

Step 2: Include Jars

Include following Jars in local accessible folder.
activemq-all-5.5.1-fuse-07-11.jar
geronimo-jms_1.1_spec-1.1.1.jar
log4j-1.2.16.jar
slf4j-api-1.6.4.jar
slf4j-log4j12-1.6.4.jar
spring-jms-3.0.6.RELEASE.jar

Step 3: Add External Jars in dtx.ini


Include above mentioned jars in External jar section dtx.ini file. (replace home/aad/tmp with your folder path from root)
jar1=/home/aad/tmp/activemq-all-5.5.1-fuse-07-11.jar
jar2=/ home / aad /tmp/geronimo-jms_1.1_spec-1.1.1.jar
jar3=/ home / aad /tmp/log4j-1.2.16.jar
jar4=/ home / aad /tmp/slf4j-api-1.6.4.jar
jar5=/ home / aad /tmp/slf4j-log4j12-1.6.4.jar
jar6=/ home / aad /tmp/spring-jms-3.0.6.RELEASE.jar

Step 4: Command

-T -HDR -ICTXFURL tcp://<brokerURL>:<port>
 -ICTXF org.apache.activemq.jndi.ActiveMQInitialContextFactory
-CFN "connectionFactory"
-QN " testQueue"
Where
connectionFactory – JNDI Connection Factory Name
testQueue – JNDI Queue Name