Amq 使用+springboot
AMQ是JMS 是java的标准
spring 提供了 JmsTemplate @JmsListerner @EnableJms
使用:
配置
@Configuration
public class AmqConfig {
//配置Amq的连接池
@Bean(name = "primaryMqConnectionFactory")
@Primary
public ActiveMQConnectionFactory primaryMqConnectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
String brokerUrl = environment.getProperty("spring.activemq.broker-url");
factory.setBrokerURL(brokerUrl);
String userName = environment.getProperty("spring.activemq.user");
factory.setUserName(userName);
String passWord = environment.getProperty("spring.activemq.password");
factory.setPassword(passWord);
factory.setCloseTimeout(2000);
factory.setConnectResponseTimeout(2000);
factory.setSendTimeout(2000);
return factory;
}
//Amq的jmsTemplate 和jdbc、redis的类似 操作mq
@Bean(name = "primaryTemplate")