Este contenido no está disponible en el idioma seleccionado.

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:
  1. 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>
    
    Copy to Clipboard Toggle word wrap
  2. 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"/>
    Copy to Clipboard Toggle word wrap
  3. 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>
    Copy to Clipboard Toggle word wrap
  4. 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")
    Copy to Clipboard Toggle word wrap
  5. 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)
    Copy to Clipboard Toggle word wrap
  6. 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>
    Copy to Clipboard Toggle word wrap
  7. 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);
    Copy to Clipboard Toggle word wrap
  8. 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>
    Copy to Clipboard Toggle word wrap
  9. 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>
    Copy to Clipboard Toggle word wrap
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2026 Red Hat