Este conteúdo não está disponível no idioma selecionado.
22.11. Configuring the HornetQ JCA Adapter for Remote Connections
Procedure 22.11. Configure an RA adapter to connect to two remote JBoss EAP instances
Before configuring the HornetQ RA to connect to remote EAP instance, we must create two connectors that point to remote JBoss EAP instances:
- Create outbound socket bindings:
<outbound-socket-binding name="remote-jms-server-a"> <remote-destination host="${remote.jms.server.one.bind.address:127.0.0.1}" port="${remote.jms.server.one.bind.port:5445}"/> </outbound-socket-binding> <outbound-socket-binding name="remote-jms-server-b"> <remote-destination host="${remote.jms.server.two.bind.address:127.0.0.1}" port="${remote.jms.server.two.bind.port:5545}"/> </outbound-socket-binding>
- Create two netty connectors:
<netty-connector name="netty-remote-node-a" socket-binding="remote-jms-server-a"/> <netty-connector name="netty-remote-node-b" socket-binding="remote-jms-server-a"/>
- Create the RA configuration using the two netty connectors:
<pooled-connection-factory name="hornetq-remote-ra"> <inbound-config> <use-jndi>true</use-jndi> <jndiparams>java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory;java.naming.provider.url=remote://${remote.jms.server.one.bind.address}:4447,${remote.jms.server.two.bind.address}:4547;java.naming.security.principal=${user.name};java.naming.security.credentials=${user.password}</jndi-params> </inbound-config> <transaction mode="xa"/> <user>${user.name}</user> <password>${user.password}</password> <connectors> <connector-ref connector-name="netty-remote-node-a"/> <connector-ref connector-name="netty-remote-node-b"/> </connectors> <entries> <entry name="java:/RemoteJmsXA"/> </entries> </pooled-connection-factory>
- Annotate the MDB to use the resource adapter using the @ResourceAdapter annotation:
@MessageDriven(name = "InQueueMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "${hornetq.in.queue.short}"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "useJNDI",propertyValue = "true") },mappedName = "${hornetq.inf.queue.long}") @ResourceAdapter("hornetq-remote-ra")
- Run the following CLI commands to enable property substitution in order to use properties in deployment descriptors:
/subsystem=ee:write-attribute(name=jboss-descriptor-property-replacement,value=true) /subsystem=ee:write-attribute(name=spec-descriptor-property-replacement,value=true) /subsystem=ee:write-attribute(name=annotation-property-replacement,value=true)
- Create an external context to find the remote destinations in order to send message from the MDB:
<bindings> <external-context name="java:global/remote" module="org.jboss.remote-naming" class="javax.naming.InitialContext"> <environment> <property name="java.naming.factory.initial" value="org.jboss.naming.remote.client.InitialContextFactory"/> <property name="java.naming.provider.url" value="remote://${remote.jms.server.one.bind.address:ragga}:4447,${remote.jms.server.two.bind.address:ragga}:4547"/> <property name="java.naming.security.principal" value="${user.name}"/> <property name="java.naming.security.credentials" value="${user.password}"/> </environment> </external-context> </bindings>
- The MDB code would look like:
@MessageDriven(name = "InQueueMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "${hornetq.in.queue.short}"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "useJNDI",propertyValue = "true"), @ActivationConfigProperty(propertyName = "hA", propertyValue = "true") },mappedName = "${hornetq.inf.queue.full}") @ResourceAdapter("hornetq-remote-ra") public class InQueueMDB implements MessageListener { private static final Logger log = Logger.getLogger(InQueueMDB.class); @Resource(lookup = "java:global/remote") private InitialContext context; @Resource( name = "${hornetq.jms.connection}") private ConnectionFactory qcf; public void onMessage(Message message){ try { if ( message instanceof TextMessage){ Object obj = (Queue) context.lookup("/jms/queue/outQueue"); qConnection = (QueueConnection) qcf.createConnection("quickuser","quick123+"); qSession = qConnection.createQueueSession(true, Session.SESSION_TRANSACTED); qSender = qSession.createSender(outQueue); qSender.send(message);
- You must remember that the hornetq RA module contains remoting-naming dependency for the MDB code given above to work:
<module xmlns="urn:jboss:module:1.1" name="org.hornetq.ra"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <resource-root path="hornetq-ra-2.3.25.Final-redhat-1.jar"/> <!-- Insert resources here --> </resources> <dependencies> <module name="org.hornetq"/> <module name="org.jboss.as.transactions"/> <module name="org.jboss.as.messaging"/> <module name="org.jboss.jboss-transaction-spi"/> <module name="org.jboss.logging"/> <module name="org.jboss.remote-naming"/> <module name="javax.api"/> <module name="javax.jms.api" /> <module name="org.jboss.jts"/> <module name="org.jboss.netty"/> <module name="org.jgroups"/> <module name="javax.resource.api"/> </dependencies> </module>
- You must also add org.hornetq to global modules so the JMS API is visible to the application:
<global-modules> <module name="org.jboss.common-core" slot="main"/> <module name="org.hornetq" slot="main"/> </global-modules>