码迷,mamicode.com
首页 > 编程语言 > 详细

springboot 整合ActiveMq

时间:2019-09-17 19:09:47      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:star   des   col   队列   sage   color   queue   activemq   XML   

pom.xml

 <!-- 配置ActiveMQ启动器 -->
 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
 </dependency>

创建消息队列

//创建队列
    @Bean
    public Queue queue(){
        return new ActiveMQQueue("yhood");
    }

发送消息

@Controller
@RequestMapping("queue")
public class MessageQueueController {

    //消息发送者
    @Autowired
    private JmsTemplate jmsTemplate;

    //消息队列(目的地)
    @Autowired
    private Destination destination;

    @RequestMapping("/send/{message}")
    @ResponseBody
    public String send(@PathVariable(value = "message")String message){
        jmsTemplate.convertAndSend(destination,message);
        return message;
    }

}

接收消息

@Component
public class Consumer {
    @JmsListener(destination = "yhood")
    public void  reader(String text){
        System.out.println("1号接收消息:"+text);
    }
}

 

springboot 整合ActiveMq

标签:star   des   col   队列   sage   color   queue   activemq   XML   

原文地址:https://www.cnblogs.com/yhood/p/11536049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!