简体   繁体   English

Servlet到远程ActiveMQ

[英]Servlet to remote ActiveMQ

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. 我正在尝试使用JMS从servlet(在Apache Tomcat上运行)向运行在同一系统上不同VM中的ActiveMQ发送消息。

Things i have tried: 我尝试过的事情:

  1. Running ActiveMQ on my system. 在我的系统上运行ActiveMQ。
  2. Wrote a client (Java app) (Producer) to create messages. 编写了一个客户端(Java应用程序)(生产者)来创建消息。
  3. Wrote a client (Java app) (Consumer) to receive those messages. 编写了一个客户端(Java应用程序)(消费者)以接收那些消息。

The above setup works fine. 上面的设置工作正常。

Now, i have a servlet, which looks up the resources via JNDI. 现在,我有一个servlet,它通过JNDI查找资源。 This is the configuration of context.xml in META-INF directory of Tomcat. 这是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>

I'm able to lookup these resources from the sevlet. 我可以从sevlet查找这些资源。 The message is sent. 消息已发送。 But i think it is not reaching the ActiveMQ. 但是我认为它还没有达到ActiveMQ。 Any ideas why ? 有什么想法吗?

I feel it is sending it to some other destination vm://localhost running within the container? 我感觉它正在将其发送到容器中运行的其他目标vm://localhost which is not what i want. 这不是我想要的。 I'm new to MOM. 我是MOM的新手。

If someone could tell me how to send a JMS message from a servlet to a remote Broker, it would be great. 如果有人可以告诉我如何从servlet向远程Broker发送JMS消息,那将是很好的。

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. 如果要通过JNDI查找指向tcp:// localhost:61616上ActiveMQ实例的连接,则该连接不是远程代理。 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. 那是在本地计算机上的端口61616上运行的代理。如果要与另一台计算机上的远程代理建立连接,则将localhost替换为IP地址。

Bruce 布鲁斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM