Pull request Compare This branch is 250 commits behind jboss-switchyard:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
src
Readme.md
pom.xml

Readme.md

SwitchYard HornetQ Component

This module contains a SwitchYard HornetQ component enabling SwitchYard to consumer and produce messages to and from HornetQ native queues.

This module also contains a HornetQ Camel Component. This component has not dependencies on Camel's JMS Component and hence has no dependencies to Spring. The reason for writing the HornetQ Component for Camel was to avoid these dependencies.

HornetQ Service Binding

A HornetQ service binding acts as a gateways/entrypoint into SwitchYard.

    <sca:composite>

        <sca:service name="HornetQService">
            <hornetq:binding.hornetq>
                <hornetq:config>
                   <hornetq:connector>
                      <hornetq:factoryClass>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</hornetq:factoryClass>
                   </hornetq:connector>
                   <hornetq:queue>jms.queue.consumer</hornetq:queue>
                </hornetq:config>
            </hornetq:binding.hornetq>
        </sca:service>
    
        <sca:component name="ComponentName">
            <bean:implementation.bean class="org.switchyard.component.hornetq.deploy.support.HornetQServiceImpl"/>
            <sca:service name="HornetQService">
                <sca:interface.java interface="org.switchyard.component.hornetq.deploy.support.HornetQService"/>
            </sca:service>
        </sca:component>
    
    </sca:composite>

</switchyard>

The complete list of configuration options available can be found in the schema hornetq-v1.xsd

HornetQ Reference Binding

A HornetQ Reference Binding allows a service to send messages to HornetQ queues. For example:

<sca:composite>

    <sca:component name="OrderComponent">
        <bean:implementation.bean class="org.switchyard.component.hornetq.support.OrderServiceImpl"/>
        <sca:service name="OrderService">
            <sca:interface.java interface="org.switchyard.component.hornetq.support.OrderService"/>
        </sca:service>
        <sca:reference name="WarehouseService"/>
    </sca:component>
    
    <sca:reference name="WarehouseService" promote="WarehouseService">
        <sca:interface.java interface="org.switchyard.component.hornetq.support.WarehouseService"/>
        <hornetq:binding.hornetq>
            <hornetq:operationSelector operationName="processOrder"/>
            <hornetq:config>
                <hornetq:connector>
                   <hornetq:factoryClass>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</hornetq:factoryClass>
                </hornetq:connector>
                <hornetq:queue>jms.queue.producer</hornetq:queue>
            </hornetq:config>
        </hornetq:binding.hornetq>
    </sca:reference>
    
</sca:composite>
In the above configuration we have defined a component named _OrderComponent_ that has a service named _OrderService_. This service is implemented by the POJO _OrderServiceImpl_ :
@Service(OrderService.class)
public class OrderServiceImpl implements OrderService {

    @Inject @Reference 
    private WarehouseService warehouseService;

    @Override
    public void sendOrder(final String order)
    {
        warehouseService.processOrder(order);
    }
}

If you look at the definition of the OrderComponent it has a reference declared:

<sca:reference name="WarehouseService"/>

This reference will be injected into OrderServiceImpl by the SwitchYard Bean component. What is injected will be a proxy that will delegate to the HornetQ component, which is configured in the hornetq:binding.hornetq section in the config. When the call processOrder is called, the order will be send to the HornetQ queue jms.queue.producer.


Using HornetQ Camel Component

Using the HornetQ Camel component is very simpliar to using other components in Camel.

Camel Spring XML DSL configuration

Example of configuring the HornetQ component using URI properties:

   <bean id="transportConfigBean" class="org.hornetq.api.core.TransportConfiguration">
       <constructor-arg value="org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"/>
   </bean>

   <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
       <route id="fromCamelComponent">
           <from uri="hornetq:jms.queue.input?transportConfiguration=#transportConfigBean"/>
           <log message="From Camel Component body: ${body}"/>
        </route>
    </camelContext>
</beans>

In the above configuration we have specified the transportConfiguration property to be a reference to a bean in the Camel Registry. Any of the other set methods on the HornetQEndpoint class are available in the same manner.

Example of creating the HornetQ component as a Spring Bean:

    <bean id="hornetq" class="org.switchyard.component.hornetq.HornetQComponent">
        <property name="transportConfiguration">
	       <bean class="org.hornetq.api.core.TransportConfiguration">
	           <constructor-arg value="org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"/>
		   </bean>
        </property>
    </bean>

   <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
       <route id="fromCamelComponent">
           <from uri="hornetq:jms.queue.input"/>
           <log message="From Camel Component body: ${body}"/>
        </route>
    </camelContext>
</beans>