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. opencv学习之路(32)、角点检测

    一.角点检测的相关概念 二.Harris角点检测——cornerHarris() 参考网址: http://www.cnblogs.com/ronny/p/4009425.html #include ...

  2. topcoder srm 575 div1

    problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...

  3. 使用NVM管理Node - Windows

    安装 NVM NVM 下载:https://github.com/coreybutler/nvm-windows 安装 Node 注意:如果没有FQ默认源可能安装npm失败,请参考下一节“安装 NPM ...

  4. memcached、cookie、session

    Memcached(一个高性能的分布式的内存对象缓存系统) 可用来分担数据库的压力.通过在内存里维护一个统一的巨大的hash表,memcached能存储各种各样的数据,包括图像.视频.文件.以及数据库 ...

  5. CentOS7安装GUI图形界面

    本文转自centOS7下安装GUI图形界面,侵权删. 1. 在命令行下 输入下面的命令来安装Gnome包. # yum groupinstall "GNOME Desktop" & ...

  6. PageRank算法实现

    基本原理 在互联网上,如果一个网页被很多其他网页所链接,说明它受到普遍的承认和信赖,那么它的排名就高.这就是PageRank的核心思想. 引用来自<数学之美>的简单例子: 网页Y的排名应该 ...

  7. Java基础知识盘点(二)- 集合篇

    List和Set区别 List和Set都是继承Collection接口 List特点:元素有放入顺序,元素可重复 Set特点:元素无放入顺序,元素不可重复 Set和List对比: Set:检索元素效率 ...

  8. python实现列表去重的方法

    >>> l=[,,,,,,] >>> list(set(l)) [, , , ] >>>

  9. 压测过程中使用nmon对服务器资源的监控

    1.nmon工具的下载和安装: 官网:http://nmon.sourceforge.net/pmwiki.php 下载完成后进行解压,更改权限:chmod 777 2.查看linux系统的版本,再使 ...

  10. pytest--fixture参数化的实现方式和执行顺序

    之前看到fixture函数可以通过添加,params参数来实现参数化,后续看到了悠悠 的博客,可以通过@pytest.mark.parametrize来实现,现在做一个总结 实现方式一 通过param ...