1、添加依赖

<!-- activeMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<!-- activeMQ的连接池 -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>

2、application.properties配置

spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.user=admin
spring.activemq.password=admin
#queue和topic不能同时使用(我不会同时使用),使用topic的时候,把下面这行解除注释
#spring.jms.pub-sub-domain=true
spring.activemq.pool.enabled=false
spring.activemq.pool.max-connections=

3、生产者

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ProducerController { @Autowired
private JmsMessagingTemplate jmsMessagingTemplate; @Autowired
private Queue queue; @Autowired
private Topic topic; /*
* 消息生产者
*/
@RequestMapping("/sendQueueMsg")
public void sendQueueMsg(String msg) {
this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
} @RequestMapping("/sendTopicMsg")
public void sendTopicMsg(String msg) {
// 指定消息发送的目的地及内容
System.out.println("@@@@@@@@@@@@@@" + msg);
this.jmsMessagingTemplate.convertAndSend(this.topic, msg);
}
}

4、消费者

import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ConsumerController { /**
* 监听和读取queue消息
* @param message
*/
@JmsListener(destination="active.queue")
public void readActiveQueue(String message) {
System.out.println("接受到:" + message);
//TODO something
} /**
* 监听和读取topic消息
* @param message
*/
@JmsListener(destination="active.topic")
public void readActiveTopic(String message) {
System.out.println("接受到:" + message);
//TODO something
}
}

5、发布/订阅的主题名称

import javax.jms.Queue;
import javax.jms.Topic; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms; @Configuration
@EnableJms
public class JmsConfig { private static final String QUEUE_NAME = "active.queue"; private static final String TOPIC_NAME = "active.topic"; @Bean
public Queue queue(){
return new ActiveMQQueue(QUEUE_NAME);
} @Bean
public Topic topic(){
return new ActiveMQTopic(TOPIC_NAME);
}
}

测试

浏览器输入:

http://localhost:8080/sendQueueMsg?msg=dddddd

SpringBoot配置ActiveMQ的更多相关文章

  1. springBoot配置activeMq点对点模式消费信息以及独占模式消费如何设置

    1.在pom文件中引入对应jar包 <!--activeMQ start--> <dependency> <groupId>org.springframework. ...

  2. SpringBoot配置activemq消息队列

    1.配置pom相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  3. SpringBoot JMS(ActiveMQ) 使用实践

    ActiveMQ 1. 下载windows办的activeMQ后,在以下目录可以启动: 2. 启动后会有以下提示 3. 所以我们可以通过http://localhost:8161访问管理页面,通过tc ...

  4. Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ

    集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...

  5. springboot与ActiveMQ整合

    前言 很多项目, 都不是一个系统就做完了. 而是好多个系统, 相互协作来完成功能. 那, 系统与系统之间, 不可能完全独立吧? 如: 在学校所用的管理系统中, 有学生系统, 资产系统, 宿舍系统等等. ...

  6. SpringBoot配置(1) 配置文件application&yml

    SpringBoot配置(1) 配置文件application&yml 一.配置文件 1.1 配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的. application ...

  7. SpringBoot集成ActiveMQ

    前面提到了原生API访问ActiveMQ和Spring集成ActiveMQ.今天讲一下SpringBoot集成ActiveMQ.SpringBoot就是为了解决我们的Maven配置烦恼而生,因此使用S ...

  8. SpringBoot配置属性之MQ

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  9. SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...

随机推荐

  1. 富文本编辑,xss攻击

    富文本编辑 KindEditor 在线HTML编辑器 http://kindeditor.net/doc.php 下载成功,解压放到项目中去 查看官方文档进行操作 xss攻击 XSS攻击全称跨站脚本攻 ...

  2. dict字典的一些优势和劣势

    01. 键必须是可散列的一个可散列的对象必须满足以下要求. (1) 支持 hash() 函数,并且通过 __hash__() 方法所得到的散列值是不变的. (2) 支持通过 __eq__() 方法来检 ...

  3. ojdbc包加入本地仓库

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar - ...

  4. Java集合源码分析之LinkedList

    1. LinkedList简介 public class LinkedList<E> extends AbstractSequentialList<E> implements ...

  5. 大数据: 完全分布式Hadoop集群-HBase安装

            HBase 是一个开源的非关系(NoSQL)的可伸缩性分布式数据库.它是面向列的,并适合于存储超大型松散数据.HBase适合于实时,随机对Big数据进行读写操作的业务环境.   本文基 ...

  6. js添加的元素无法触发click事件

    动态生成的元素,使用.on绑定事件,比如$(document).on("click",".divclick",function(){})

  7. 小程序使用阿里巴巴TTF字体文件以及图标

    转话地址https://transfonter.org 第一步:下载需要的字体图标 进入阿里图标官网http://iconfont.cn/搜索自己想要的图标,如这里需要一个购物车的图标,流程为: 搜索 ...

  8. shell 按行读取文件的内容

    test.py: #coding=utf- import subprocess compilePopen = subprocess.Popen('gcc haha',shell=True,stderr ...

  9. [转]OpenStreetMap/Google/百度/Bing瓦片地图服务(TMS)

    转自:https://blog.csdn.net/youngkingyj/article/details/23365849 开源与成熟商业的瓦片地图服务(TMS  2  WMTS),都有如下共同的特性 ...

  10. WSGI协议主要包括server和application两部分:

    WSGI server负责从客户端接收请求,将request转发给application,将application返回的response返回给客户端:WSGI application接收由server ...