1 Reply Latest reply on Jun 30, 2014 4:08 PM by kcbabo

    JMS Queue inside an application

    bhaskarsk

      Hello,

       

      I have a requirement where my gateway binding is a TCP binding and internally i need to store the TCP messages in a queue( JMS queue), which will be processed further by another component.

      TCP Component -> Queue Component -> MessageHandler Component.

       

      i have tried two approaches for this.

       

      1) create a composite service with JMS binding and then from the TCP component service push to the JMS service queue using HornetQ Client.

      TCP Composite -> TCP Component Service(Using Hornetq) -> Queue Component( promoted as JMS Service)

      2) create a composite reference for JMS service and push the message.

      TCP Composite -> TCP Component Service(Using CompositeReference of JMS Service) -> Queue Component( promoted as JMS Service)

      Although both works, which is better/correct?

       

      On the other side, i will have two composite services defined in my application (first is TCP,  second composite service is JMS service, as i want to use JMS queue for internal memory queue) and the interaction between the TCP component and the QueueComponent( which is promoted as composite service) is happening through Gateway (JMS) binding. Is this approach correct?

       

      <?xml version="1.0" encoding="ASCII"?>
      <sy:switchyard xmlns:bean="urn:switchyard-component-bean:config:1.1" xmlns:camel="urn:switchyard-component-camel:config:1.1" xmlns:camel_1="urn:switchyard-component-camel-core:config:1.1" xmlns:jca="urn:switchyard-component-jca:config:1.1" xmlns:jms="urn:switchyard-component-camel-jms:config:1.1" xmlns:netty="urn:switchyard-component-camel-netty:config:1.1" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:sy="urn:switchyard-config:switchyard:1.1" name="switchyard-example-netty" targetNamespace="urn:com.example.switchyard:switchyard-example-netty:1.0">
        <sca:composite name="switchyard-example-netty" targetNamespace="urn:com.example.switchyard:switchyard-example-netty:1.0">
          <sca:component name="NettyListenerBean">
            <bean:implementation.bean class="com.example.switchyard.switchyard_example_netty.NettyListenerBean"/>
            <sca:service name="NettyListener">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.NettyListener"/>
            </sca:service>
            <sca:reference name="RouteMap">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.RouteMap"/>
            </sca:reference>
          </sca:component>
          <sca:service name="NettyListener" promote="NettyListenerBean/NettyListener">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.NettyListener"/>
            <netty:binding.tcp name="tcp1">
              <sy:operationSelector operationName="readData"/>
              <netty:host>0.0.0.0</netty:host>
              <netty:port>9998</netty:port>
              <netty:allowDefaultCodec>false</netty:allowDefaultCodec>
              <netty:sync>false</netty:sync>
            </netty:binding.tcp>
          </sca:service>
        <sca:component name="RouteMap">
            <camel:implementation.camel>
              <camel:xml path="routeMapper.xml"/>
            </camel:implementation.camel>
            <sca:service name="RouteMap">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.RouteMap"/>
            </sca:service>
            <sca:reference name="QueueService1">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            </sca:reference>
            <sca:reference name="QueueService2">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            </sca:reference>
            <sca:reference name="QueueService3">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            </sca:reference>
          </sca:component>
          <sca:reference name="QueueService1" multiplicity="0..1" promote="RouteMap/QueueService1">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue1">
              <jms:queue>EventQueue1</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:reference>
        <sca:reference name="QueueService2" multiplicity="0..1" promote="RouteMap/QueueService2">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue2">
              <jms:queue>EventQueue2</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:reference>
        <sca:reference name="QueueService3" multiplicity="0..1" promote="RouteMap/QueueService3">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue3">
              <jms:queue>EventQueue3</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:reference>
          <sca:component name="ConsumerQueueServiceBean">
            <bean:implementation.bean class="com.example.switchyard.switchyard_example_netty.ConsumerQueueServiceBean"/>
            <sca:service name="ConsumerQueueService">
              <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            </sca:service>
          </sca:component>
          <sca:service name="ConsumerQueueService1" promote="ConsumerQueueServiceBean/ConsumerQueueService">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue1">
              <sy:operationSelector operationName="handleEvent"/>
              <jms:queue>EventQueue1</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:service>
          <sca:service name="ConsumerQueueService2" promote="ConsumerQueueServiceBean/ConsumerQueueService">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue2">
              <sy:operationSelector operationName="handleEvent"/>
              <jms:queue>EventQueue2</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:service>
          <sca:service name="ConsumerQueueService3" promote="ConsumerQueueServiceBean/ConsumerQueueService">
            <sca:interface.java interface="com.example.switchyard.switchyard_example_netty.QueueService"/>
            <jms:binding.jms name="EventQueue3">
              <jms:queue>EventQueue3</jms:queue>
              <jms:connectionFactory>#ConnectionFactory</jms:connectionFactory>
            </jms:binding.jms>
          </sca:service>    
        </sca:composite>
        <sy:domain>
          <sy:properties>
            <sy:property name="org.switchyard.handlers.messageTrace.enabled" value="true"/>
          </sy:properties>
        </sy:domain>
      </sy:switchyard>
      
        • 1. Re: JMS Queue inside an application
          kcbabo

          While both approaches will work, using a reference to invoke the JMS-based service (option 2) is preferred as the external interaction is represented as a dependency and the details of the binding used to perform the invocation are kept out of your service implementation.

          1 of 1 people found this helpful