Servlet 到远程 ActiveMQ
我正在尝试使用 JMS 从 servlet(在 Apache Tomcat 上运行)向在同一系统上的不同 VM 中运行的 ActiveMQ 发送消息。
我尝试过的事情:
- 在我的系统上运行 ActiveMQ。
- 编写了一个客户端(Java 应用程序)(Producer)来创建消息。
- 编写一个客户端(Java 应用程序)(消费者)来接收这些消息。
上面的设置工作正常。
现在,我有一个 servlet,它通过 JNDI 查找资源。这是Tomcat META-INF目录下context.xml的配置。
<Context>
<Resource
name="jms/ConnectionFactory"
auth="Container"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL=" tcp://localhost:61616"
/>
</Context>
我可以从 sevlet 查找这些资源。消息已发送。但我认为它没有到达 ActiveMQ。有什么想法吗?
我觉得它正在将其发送到容器内运行的其他目的地vm://localhost
?这不是我想要的。我是妈妈的新人。
如果有人能告诉我如何将 JMS 消息从 servlet 发送到远程 Broker,那就太好了。
I'm trying to send a message using JMS from a servlet (running on Apache Tomcat) to ActiveMQ running in a different VM on the same system.
Things i have tried:
- Running ActiveMQ on my system.
- Wrote a client (Java app) (Producer) to create messages.
- Wrote a client (Java app) (Consumer) to receive those messages.
The above setup works fine.
Now, i have a servlet, which looks up the resources via JNDI. This is the configuration of context.xml in META-INF directory of Tomcat.
<Context>
<Resource
name="jms/ConnectionFactory"
auth="Container"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL=" tcp://localhost:61616"
/>
</Context>
I'm able to lookup these resources from the sevlet. The message is sent. But i think it is not reaching the ActiveMQ. Any ideas why ?
I feel it is sending it to some other destination vm://localhost
running within the container? which is not what i want. I'm new to MOM.
If someone could tell me how to send a JMS message from a servlet to a remote Broker, it would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您通过 JNDI 查找指向 tcp://localhost:61616 处的 ActiveMQ 实例的连接,则该连接不是远程代理。这是在本地计算机上的端口 61616 上运行的代理。如果您希望连接到另一台计算机上的远程代理,请将 localhost 替换为 IP 地址。
布鲁斯
If you are looking up the connection via JNDI that is pointed at an ActiveMQ instance at tcp://localhost:61616, that is not a remote broker. That is a broker running on the local machine on port 61616. If you want the connection to made to a remote broker on another machine, then replace localhost with the IP address.
Bruce