如何配置Apache QPID以使用RabbitMQ?

时间:2016-04-21 20:31:33

标签: jms rabbitmq amqp qpid

您好我很乐意了解如何编写简单的Java独立程序,使用Apache QPID jms客户端向RabbitMQ发送和接收消息。

如何从QPID创建初始上下文,然后从RabbitMQ中查找目标?

我在互联网上搜索了很多,但我找不到任何解决方案,这有助于我更好地理解在这两者之间建立联系。

我认为这应该是可能的,因为RabbitMQ和QPID都在使用AMQP协议。

我尝试使用以下jndi.properties创建Context:

java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory connectionfactory.myFactoryLookup = amqp://:5672 queue.myQueueLookup = queue

以下代码:

Context context = new InitialContext();

        ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
        Destination queue = (Destination) context.lookup("myQueueLookup");

        Connection connection = factory.createConnection(USER, PASSWORD);
        connection.setExceptionListener(new MyExceptionListener());
        connection.start();

但我得到一个例外:

javax.jms.JMSException: An existing connection was forcibly closed by the remote host
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:66)
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:88)
at org.apache.qpid.jms.JmsConnection.createResource(JmsConnection.java:548)
at org.apache.qpid.jms.JmsConnection.createResource(JmsConnection.java:532)
at org.apache.qpid.jms.JmsConnection.connect(JmsConnection.java:447)
at org.apache.qpid.jms.JmsConnection.start(JmsConnection.java:301)
at com.test.Sender.main(Sender.java:36)
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)

有人知道可能是什么原因,并建议代码是否有问题???

提前致谢!

0 个答案:

没有答案