Reputation: 5406
From an EJB or a POJO deployed on Glassfish I can connect to HornetMQ with the following code, after I add to classpath the necessary hornet specific jars:
Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
// server name
properties.put("java.naming.provider.url", "jnp://hostname:1099");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
InitialContext initialContext = new InitialContext(properties);
// queue name
Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
// connection factory
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
Connection conn = connectionFactory.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
// ...
But I want to do the same from a Message Driven Bean.
With a MDB it's very easy if I use the embedded Glassfish provider; but how do I configure GF to use a remote provider?
Any ideas? Thank you!
EDIT: to make things a little clearer; a typical MDB looks something like this:
@MessageDriven(mappedName = "/queue/exampleQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MessageProcessor implements MessageListener {
public MessageProcessor() {
}
public void onMessage(Message message) {
}
}
But in this case, the MDB will look for "/queue/exampleQueue" on the local server not the remote one.
Basically my question is how do I configure GF to look for the remote server (as in the first snippet) when using a MDB?
Upvotes: 2
Views: 11408
Reputation: 5406
After some more digging I found a solution on these forums
To enable a MDB to "talk" to a remote HornetQ provider follow these steps:
hornetq-ra.rar
to glassfish using admin console (you'll find it in the "libs" folder in the hornetq folder)<gf_install_dir>/domains/<your_dmain>/applications/hornetq-ra/META-INF/ra.xml
and comment out the following section: <config-property>
<description>The transport configuration. These values must be in the form of key=val;key=val;</description>
<config-property-name>ConnectionParameters</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>server-id=0</config-property-value>
</config-property>
Apparently leaving server-id
will cause an exception on deployment time.
hornetq-core-client.jar
, hornetq-jms-client.jar
, hornetq-logging.jar
and netty.jar
<ejb-name>MessageProcessor</ejb-name> <!-- MDB class name -->
<jndi-name>ExampleMDB</jndi-name>
<mdb-resource-adapter>
<!-- The resource adapter mid element ties the generic ra for JMS
with this particular MDB -->
<resource-adapter-mid>hornetq-ra</resource-adapter-mid>
<activation-config>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>/queue/exampleQueue</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>ConnectorClassName</activation-config-property-name>
<activation-config-property-value>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>ConnectionParameters</activation-config-property-name>
<activation-config-property-value>host=hostname;port=5445</activation-config-property-value>
</activation-config-property>
<!--
<activation-config-property>
<activation-config-property-name>UserName</activation-config-property-name>
<activation-config-property-value>user</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>Password</activation-config-property-name>
<activation-config-property-value>pass</activation-config-property-value>
</activation-config-property>
-->
</activation-config>
</mdb-resource-adapter>
</ejb>
@MessageDriven(mappedName = "ExampleMDB")
public class MessageProcessor implements MessageListener {
public MessageProcessor() {
}
public void onMessage(Message message) {
System.out.println("message received");
}
}
Upvotes: 3
Reputation: 3271
You're trying to configure a remote JMS provider. There's a good article here
http://www.packtpub.com/article/configuring-jms-resources-in-glassfish-1
However, I'm not sure it will work with HornetMQ, you might have to use a remote instance of OpenMQ
Upvotes: 1