【发布时间】:2020-07-28 21:33:54
【问题描述】:
我想使用 SpringBoot 向 ActiveMQ 队列发送消息。应用程序在发送后应该终止,但它保持活动状态。
这是我的应用程序代码:
@SpringBootApplication
public class TestJmsClient implements CommandLineRunner {
private static final String QUEUE_NAME = "myQueue";
@Autowired
private JmsTemplate jmsTemplate;
public static void main(String[] args) {
new SpringApplicationBuilder(TestJmsClient.class).bannerMode(Mode.OFF).run(args);
}
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.BYTES);
converter.setTypeIdPropertyName("_type");
return converter;
}
@Override
public void run(String... args) throws Exception {
jmsTemplate.convertAndSend(QUEUE_NAME, new MyObject());
}
}
使用以下不带任何父级的依赖项 (Maven):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
还有一行application.properties:
spring.activemq.broker-url=failover:(tcp://localhost:61616)
消息已发送到队列,但应用程序并未停止。线程转储向我显示,ActiveMQ Transport: tcp://localhost/127.0.0.1:61616 线程正在运行。
我需要不同的ConnectionFactory 吗?或者我可以在发送消息后立即终止应用程序吗?
注意:没有 JMS 内容,应用程序将终止。 注意:我使用的是标准 ActiveMQ 安装。
谢谢:)
【问题讨论】:
标签: java spring-boot jms spring-jms