您现在的位置是:首页 > 文章详情

ActiveMQ

日期:2018-10-28点击:480

-1.导包

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

-2.配置信息

@Configuration public class ActiveMQConfig { // 提供生产bean的方法 @Bean public Queue createQueue() { return new ActiveMQQueue("bos.queue"); } @Bean public Topic createTopic() { return new ActiveMQTopic("bos.topic"); } }

-3.使用 --生产者

@Autowired private Queue queue; @Autowired private JmsMessagingTemplate jmsMessagingTemplate; public void run(){ /* 前台获取数据 telephone:137****7790 code:*** */ //准备消息 ActiveMQMapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString("telephone",telephone); mapMessage.setString("code",code); //发送消息 jmsMessagingTemplate.convertAndSend(queue,mapMessage); }

-4.消费者 --消费

package com.czxy.sms.consumer; import org.springframework.jms.annotation.JmsListener; import org.springframework.stereotype.Component; import javax.jms.MapMessage; import javax.jms.Message; @Component public class SmsConsumer { @JmsListener(destination = "java1.bos.sms") public void recive(Message message) { try { MapMessage mapMessage = (MapMessage) message; String telephone = mapMessage.getString("telephone"); String code = mapMessage.getString("code"); System.out.println(telephone + ":" + code); // 发送短信,调用SMSutil // SmsUtil.sendSms(telephone,code); } catch (Exception e) { } } }
原文链接:https://yq.aliyun.com/articles/658514
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章