从消息驱动 Bean (MDB) 连接到远程 JMS 提供程序
在将必要的 hornet 特定 jar 添加到类路径后,我可以使用以下代码从部署在 Glassfish 上的 EJB 或 POJO 连接到 HornetMQ:
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();
// ...
但我想从消息驱动 Bean 执行相同操作。
对于 MDB,如果我使用嵌入式 Glassfish 提供程序,则非常容易;但如何配置 GF 以使用远程提供商?
有什么想法吗?谢谢你!
编辑:让事情变得更清楚一些;典型的 MDB 看起来像这样:
@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) {
}
}
但在这种情况下,MDB 将在本地服务器而不是远程服务器上查找“/queue/exampleQueue”。
基本上我的问题是如何配置 GF 在使用 MDB 时查找远程服务器(如第一个片段中所示)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多挖掘后,我在 这些论坛 上找到了一个解决方案
,使 MDB 能够“交谈”到远程 HornetQ 提供商,请按照以下步骤操作:
hornetq-ra.rar
部署到 glassfish(您可以在 hornetq 文件夹的“libs”文件夹中找到它)< gf_install_dir>/domains//applications/hornetq-ra/META-INF/ra.xml
并注释掉以下部分:显然离开
server-id
将导致异常关于部署时间。hornetq-core-client.jar
、hornetq-jms-client.jar
、hornetq-logging.jar 和
netty.jar
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:Apparently leaving
server-id
will cause an exception on deployment time.hornetq-core-client.jar
,hornetq-jms-client.jar
,hornetq-logging.jar
andnetty.jar
您正在尝试配置远程 JMS 提供程序。这里有一篇好文章
http://www.packtpub.com/ Article/configuring-jms-resources-in-glassfish-1
但是,我不确定它是否可以与 HornetMQ 一起使用,您可能必须使用 OpenMQ 的远程实例
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