RabbitMQ 生产者不会终止
RabbitMQ producer doesn't terminates
我有一个生产者将数据发送到 RabbitMQ(版本 3.6.1)。以前我使用的是 rabbitmq-client jar,应用程序运行良好。
现在我切换到 spring-amqp 1.2.0,它也能够成功地将数据发送到 RabbitMQ 代理,但程序永远不会终止。
我在生产者端使用了以下配置。
<rabbit:connection-factory id="connectionFactory" host="localhost" port="5672" channel-cache-size="25" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue name="text_offline_queue"/>
我正在使用以下代码加载上述配置:
public static int send(String message) {
ClassPathXmlApplicationContext ctx = null;
try {
ctx = new ClassPathXmlApplicationContext(
"rabbitContext.xml");
}catch (Exception ex){
ex.printStackTrace();
System.out.println(
"Error while open/read the rabbitmq context file");
}
AmqpTemplate template = ctx.getBean(AmqpTemplate.class);
template.send(QUEUE_NAME, new Message(message.getBytes(), new MessageProperties()));
return 1;
}
}
而且程序永远不会终止(见附图)。
提前致谢
首先,1.2已经很老了;当前版本是 1.6.3.
连接工厂保持连接打开以提高效率。
当您想终止应用程序时,调用ctx.close()
,应用程序上下文将被关闭。
我有一个生产者将数据发送到 RabbitMQ(版本 3.6.1)。以前我使用的是 rabbitmq-client jar,应用程序运行良好。
现在我切换到 spring-amqp 1.2.0,它也能够成功地将数据发送到 RabbitMQ 代理,但程序永远不会终止。 我在生产者端使用了以下配置。
<rabbit:connection-factory id="connectionFactory" host="localhost" port="5672" channel-cache-size="25" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue name="text_offline_queue"/>
我正在使用以下代码加载上述配置:
public static int send(String message) {
ClassPathXmlApplicationContext ctx = null;
try {
ctx = new ClassPathXmlApplicationContext(
"rabbitContext.xml");
}catch (Exception ex){
ex.printStackTrace();
System.out.println(
"Error while open/read the rabbitmq context file");
}
AmqpTemplate template = ctx.getBean(AmqpTemplate.class);
template.send(QUEUE_NAME, new Message(message.getBytes(), new MessageProperties()));
return 1;
}
}
而且程序永远不会终止(见附图)。
提前致谢
首先,1.2已经很老了;当前版本是 1.6.3.
连接工厂保持连接打开以提高效率。
当您想终止应用程序时,调用ctx.close()
,应用程序上下文将被关闭。