此内容没有您所选择的语言版本。

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
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat