如何配置Apache QPID以使用RabbitMQ?

您好,我很乐意了解如何编写简单的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)

有人有一个想法可能是什么原因,并建议如果代码有问题?

提前致谢!

链接地址: http://www.djcxy.com/p/34125.html

上一篇: How to configure Apache QPID to work with RabbitMQ?

下一篇: QPID broker with RabbitMQ client authentication exception