本文共 1230 字,大约阅读时间需要 4 分钟。
Spring Boot支持的jms有:ActiveMQ、Artemis、HornetQ
org.springframework.boot spring-boot-starter-activemq
# ACTIVEMQ (ActiveMQProperties)spring.activemq.in-memory=true#spring.activemq.broker-url= #spring.activemq.password= #spring.activemq.user= #spring.activemq.packages.trust-all=false#spring.activemq.packages.trusted=#spring.activemq.pool.configuration.*= #spring.activemq.pool.enabled=false#spring.activemq.pool.expiry-timeout=0#spring.activemq.pool.idle-timeout=30000#spring.activemq.pool.max-connections=1
启动注解:
/** * jms队列配置 * */@Configurationpublicclass JmsConfiguration { @Bean publicQueue queue() { returnnew ActiveMQQueue("ctoedu.queue"); }}
@Componentpublicclass JmsComponent { @Autowired private JmsMessagingTemplate jmsMessagingTemplate; @Autowired private Queue queue; publicvoid send(String msg) { this.jmsMessagingTemplate.convertAndSend(this.queue, msg); } @JmsListener(destination = "ctoedu.queue") publicvoid receiveQueue(String text) { System.out.println("接受到:" + text); }}
@Autowired private JmsComponent jmsComponent; @Test public void send() { jmsComponent.send("hello world"); }
转载地址:http://sxonn.baihongyu.com/