Skip to content

mijingling/springBoot-MQ-active

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#springboot+activemq集成 ##1.在pom.xml中引入相关jar包(version至少1.4.0以上) org.springframework.boot spring-boot-starter-activemq 1.4.0.RELEASE ##2.在application.properties中配置activemq连接参数 #activemq-config spring.activemq.brokerUrl=tcp://127.0.0.1:61616 spring.activemq.user=admin spring.activemq.password=admin ##3.消息生产者配置(如果传更多参数,消息内容可以jsonString格式,也可以用序列化对象传参) public static final String BUSINESS1 = "activemq.queue"; @Autowired private JmsMessagingTemplate jmsMessagingTemplate;// 注入消息模板实例 @RequestMapping(value = "/") public String home() throws IOException { Map<String, String> msg = new HashMap<>(); msg.put("key", "hi,activeMQ"); jmsMessagingTemplate.convertAndSend(QueueList.BUSINESS1, JSON.toJSONString(msg)); return "hello springboot"; } ##4.消息消费者配置(即配置消息队列监听JmsListener) @JmsListener(destination = QueueList.BUSINESS2) public void receiveQueueObj(String txtMsg) { // 消息内容转为具体对象,数据类型更明晰 ParamVo paramVo = JSON.parseObject(txtMsg, ParamVo.class);// 推荐该转换方案 System.out.println("##activemq.queue#" + JSON.toJSONString(paramVo)); } @JmsListener(destination = QueueList.BUSINESS1) public void receiveQueue(String txtMsg) { // 消息内容转为Map<String,Object> Map<String, Object> map = JSON.parseObject(txtMsg); System.out.println("##activemq.queue#" + map); } ##5.Demo测试 a.启动activemq服务 b.启动springBoot服务(如果activemq连接配置不同,需要在application.properties中调整) c.访问http://localhost:1010 (解析接收消息为map) 或者 http://localhost:1010/2 (解析接收消息为Vo对象)

About

springboot+activemq

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages