ActiveMQ

简介: ActiveMQ

-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) {

        }

    }

}
目录
相关文章
|
8月前
|
消息中间件 Java Kafka
ActiveMQ
   MQ是消息中间件,是一种在分布式系统中应用程序借以传递消息的媒介,常用的有ActiveMQ,RabbitMQ,kafka。ActiveMQ是Apache下的开源项目,完全支持JMS1.1和J2EE1.4规范的JMS Provider实现。
89 0
ActiveMQ
|
11月前
|
消息中间件 存储 网络协议
深入了解ActiveMQ!
深入了解ActiveMQ!
187 0
|
11月前
|
消息中间件 Java Linux
|
消息中间件
ActiveMQ - SpringJMS 之 ActiveMQ
ActiveMQ - SpringJMS 之 ActiveMQ
42 0
ActiveMQ - SpringJMS 之 ActiveMQ
|
消息中间件 JSON 缓存
浅谈ActiveMQ
浅谈ActiveMQ
|
消息中间件 中间件
ActiveMQ - 基础篇(上)
ActiveMQ - 基础篇(上)
112 0
ActiveMQ - 基础篇(上)
|
消息中间件
ActiveMQ - 基础篇(下)
ActiveMQ - 基础篇(下)
115 0
ActiveMQ - 基础篇(下)
|
消息中间件 存储 缓存
ActiveMQ介绍与安装
ActiveMQ介绍与安装
209 0
ActiveMQ介绍与安装
|
消息中间件 Java Apache
消息中间件学习笔记--ActiveMQ(一、安装)
消息中间件学习笔记--ActiveMQ(一、安装)
109 0
消息中间件学习笔记--ActiveMQ(一、安装)
|
消息中间件 开发框架 前端开发
ActiveMQ介绍及安装
ActiveMQ介绍及安装
ActiveMQ介绍及安装

相关实验场景

更多