Servlet 到远程 ActiveMQ

发布于 2024-09-26 11:51:03 字数 900 浏览 0 评论 0原文

我正在尝试使用 JMS 从 servlet(在 Apache Tomcat 上运行)向在同一系统上的不同 VM 中运行的 ActiveMQ 发送消息。

我尝试过的事情:

  1. 在我的系统上运行 ActiveMQ。
  2. 编写了一个客户端(Java 应用程序)(Producer)来创建消息。
  3. 编写一个客户端(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:

  1. Running ActiveMQ on my system.
  2. Wrote a client (Java app) (Producer) to create messages.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2024-10-03 11:51:03

如果您通过 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文