Contact Us 1-800-596-4880

HornetQ integration

To integrate with HornetQ you have to configure a connection factory in Spring and reference it when creating the JMS connector. The configuration differs depending if you want to connect to a stand-alone instance of HortneQ or one that is set up as a cluster.

Connecting to a single HornetQ instance

<mule xmlns="http://www.mulesource.org/schema/mule/core"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:spring="http://www.springframework.org/schema/beans"      xmlns:jms="http://www.mulesource.org/schema/mule/jms"      xsi:schemaLocation="          http://www.mulesource.org/schema/mule/core http://www.mulesource.org/schema/mule/core/3.0/mule.xsd          http://www.mulesource.org/schema/mule/jms http://www.mulesource.org/schema/mule/jms/3.0/mule-jms.xsd          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">    <spring:bean name="connectionFactory" class="org.hornetq.jms.client.HornetQConnectionFactory">        <spring:constructor-arg>            <spring:bean class="org.hornetq.api.core.TransportConfiguration">                <spring:constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"/>                <spring:constructor-arg>                    <spring:map key-type="java.lang.String" value-type="java.lang.Object">                        <spring:entry key="port" value="5445"></spring:entry>                    </spring:map>                </spring:constructor-arg>            </spring:bean>        </spring:constructor-arg>    </spring:bean>    <jms:connector name="hornetq-connector" username="guest" password="guest"        specification="1.1" connectionFactory-ref="connectionFactory" /></mule>

Connecting to a HornetQ cluster

<mule xmlns="http://www.mulesource.org/schema/mule/core"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:spring="http://www.springframework.org/schema/beans"      xmlns:jms="http://www.mulesource.org/schema/mule/jms"      xsi:schemaLocation="          http://www.mulesource.org/schema/mule/core http://www.mulesource.org/schema/mule/core/3.0/mule.xsd          http://www.mulesource.org/schema/mule/jms http://www.mulesource.org/schema/mule/jms/3.0/mule-jms.xsd          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">    <spring:bean name="connectionFactory" class="org.hornetq.jms.client.HornetQConnectionFactory">        <spring:property name="discoveryAddress" value="231.7.7.7"/>        <spring:property name="discoveryPort" value="9876"/>        <spring:property name="discoveryRefreshTimeout" value="1000"/>        <!-- If you want the client to failover when its server is cleanly shutdown -->        <spring:property name="failoverOnServerShutdown" value="true"/>        <!-- period in milliseconds between subsequent reconnection attempts. The default value is 2000 milliseconds-->        <spring:property name="retryInterval" value="1000"/>        <!-- allows you to implement an exponential backoff between retry attempts -->        <spring:property name="retryIntervalMultiplier" value="2.0"/>        <!-- A value of -1 signifies an unlimited number of attempts. The default value is 0. -->        <spring:property name="reconnectAttempts" value="-1"/>        <!-- interesting for blocked receivers: If you're using JMS it's defined by the ClientFailureCheckPeriod attribute on a HornetQConnectionFactory  instance -->        <spring:property name="clientFailureCheckPeriod" value="1000"/>        <!-- allow the client to loadbalance when creating multiple sessions from one sessionFactory -->        <spring:property name="connectionLoadBalancingPolicyClassName" value="org.hornetq.api.core.client.loadbalance.RandomConnectionLoadBalancingPolicy"/>    </spring:bean>    <jms:connector name="hornetq-connector" username="guest" password="guest"        specification="1.1" connectionFactory-ref="connectionFactory"/></mule>

Required libraries

You need to have the following jars on the classpath

  • hornetq-core-client.jar

  • hornetq-jms.jar

  • netty.jar