-
1. Re: JMS: Best way to connect from server A to server B
jbertram Apr 16, 2012 10:17 AM (in response to dbeltran)The best way for an application in one instance of AS 7 to connect to another instance for AS 7 is by using the HornetQ JCA resource adapter. If you need to consume messages then use an MDB with the approrpriate activation configuration properties, e.g.:
@MessageDriven(name = "myMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),
@ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),
@ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=192.168.1.137;port=5445")})
If you need to send messages then configure a <pooled-connection-factory>, e.g.:
<connectors>
...
<connector name="remote-jmsxa">
<factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="host" value="my.remote.host"/>
<param key="port" value="5445"/>
</connector>
...
</connectors>
...
<jms-connection-factories>
...
<pooled-connection-factory name="remote-hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="remote-jmsxa"/>
</connectors>
<entries>
<entry name="java:/RemoteJmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
Then look-up this connection factory (i.e. "java:/RemoteJmsXA") and use it as needed.
-
2. Re: JMS: Best way to connect from server A to server B
dbeltran Apr 16, 2012 11:33 AM (in response to jbertram)Thank Justin,
Do you know where I coud find an example for the producer java code?
Best regards,
David
-
3. Re: JMS: Best way to connect from server A to server B
jbertram Apr 16, 2012 11:39 AM (in response to dbeltran)The producer code will follow the standard JMS API. You can find examples all over the Internet.
You can get a reference to the connection factory from JNDI either using a blank InitialContext or via injection.
-
4. Re: JMS: Best way to connect from server A to server B
dbeltran Apr 16, 2012 12:15 PM (in response to jbertram)Thanks again,
I asked you because I have founded another thread, https://community.jboss.org/message/721977#721977#721977, in which they are creating the destination through the session instead of the lookup operation. Its a good practice? As far I have read in the jms specification the lookup is more portable. Below is the related snipped code:
InitialContext ic = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ic.lookup(jndiConnectionFactory);
Connection connection = cf.createConnection(user, passwd);
Session session = connection.createSession(transactable, acknowledge);
Destination resourceJMS = session.createQueue(destinationn);
Best regards,
David