我正在尝试使用QPID JMS客户端向带有AMQP 1.0的RabbitMQ(版本:3.7.7)发送一条简单消息。我正在使用以下版本:
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>0.40.0</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0</version>
</dependency>
我在RabbitMQ上启用了rabbitmq_amqp1_0
插件,并在管理UI的帮助下在代理上创建了一个名称为“ queue”的队列。然后,我创建了具有以下内容的单元测试:
public class JMSIssueTest {
private static final String AMQP_URI = "amqp://localhost:5672";
private static final String QUEUE_NAME = "queue";
@Test
public void testSend() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(AMQP_URI);
try(Connection connection = factory.createConnection()){
connection.setExceptionListener(new MyExceptionListener());
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(QUEUE_NAME);
MessageProducer producer = session.createProducer(queue); // the code stops here
TextMessage message = session.createTextMessage("test");
producer.send(message);
System.out.println("send");
}
}
private static class MyExceptionListener implements ExceptionListener {
@Override
public void onException(JMSException exception) {
System.out.println("Connection ExceptionListener fired, exiting.");
exception.printStackTrace(System.out);
System.exit(1);
}
}
}
如果运行此测试,我没有收到错误,但是在控制台中,我可以看到以下输出:
DEBUG org.apache.qpid.jms.provider.amqp.builders.AmqpProducerBuilder - Creating AmqpFixedProducer for: queue
在RabbitMQ上,我可以看到协议类型为AMQP 1.0
的连接。
我错误地创建了生产者吗?