activemq安装运行及其在springboot中的queue和topic使用
安装activemq
http://activemq.apache.org/download.html
运行
运行
bin\win64\activemq.bat
访问 http://127.0.0.1:8161/admin/
用户名/密码:admin/admin
springboot使用
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
配置
spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.close-timeout=5000
spring.activemq.in-memory=false
spring.activemq.pool.max-connections=100
spring.activemq.send-timeout=3000
# spring.jms.pub-sub-domain=true 开启topic订阅,不开启就是queue
Producer
生产者
package jky.springboot.alliinone.activemq;
import javax.jms.Destination;
import javax.jms.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
@Component
public class Producer {
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;
// 使用queue
public void send(Destination destination, final String message) {
jmsMessagingTemplate.convertAndSend(destination, message + "from queue");
}
//使用topic使用
//public void send(Topic topi, final String message) {
// jmsMessagingTemplate.convertAndSend(topic, message + " from topic");
//}
// 监听out队列
@JmsListener(destination="out.queue")
public void consumerMessage(String text){
System.out.println("从out.queue队列收到的回复信息为:"+text);
}
}
Consumer
queue消费者
package jky.springboot.alliinone.activemq;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;
@Component
public class Consumer {
// 监听mytest队列,并且发送消息到out队列
@JmsListener(destination = "mytest.queue")
@SendTo("out.queue")
public String receiveQueue(String text) {
System.out.println("Consumer收到的信息为:"+text);
return "return message "+text;
}
}
ComsumerTopic
topic消费者
package jky.springboot.alliinone.activemq;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class ComsumerTopic {
// 监听sample topic
@JmsListener(destination = "sample.topic")
public void receiveTopic(String text) {
System.out.println("Consumer收到的topic信息为:"+text);
}
}
使用
队列生产者生产消息
Destination destination = new ActiveMQQueue("mytest.queue");
producer.send(destination, "I am YeJiaWei");
topic生产者生产消息
Topic topic = new ActiveMQTopic("sample.topic");
producer.send(topic, "I am YeJiaWei");
activemq安装运行及其在springboot中的queue和topic使用的更多相关文章
- activemq artemis安装运行及其在springboot中的使用
安装 创建broker 在springboot中的使用 依赖 配置 Producer Consumer Rest使用 安装 http://activemq.apache.org/artemis/dow ...
- ActiveMQ第四弹:在HermesJMS中创建ActiveMQ Session
Hermes JMS是一个开源免费的跨平台的JMS消息监听工具.它可以很方便和各种JMS框架集成和交互,可以用来监听.发送.接收.修改.存储消息等.这篇文章将讲解HermesJMS如何集成Active ...
- springboot之activemq安装与实践
环境:腾讯云centos7 注意:activemq安装插件,可能会报错.本人是主机名的问题,所以修改了主机名. vim /etc/hosts vim /etc/hostname 修改这两个文件,并重启 ...
- 以ActiveMQ为例JAVA消息中间件学习【3】——SpringBoot中使用ActiveMQ
前言 首先我们在java环境中使用了ActiveMQ,然后我们又在Spring中使用了ActiveMQ 本来这样已经可以了,但是最近SpringBoot也来了.所以在其中也需要使用试试. 可以提前透露 ...
- (二)Redis在Mac下的安装与SpringBoot中的配置
1 下载Redis 官网下载,下载 stable 版本,稳定版本. 2 本地安装 解压:tar zxvf redis-6.0.1.tar.gz 移动到: sudo mv redis-6.0.1 /us ...
- Android中插件开发篇之----动态加载Activity(免安装运行程序)
一.前言 又到周末了,时间过的很快,今天我们来看一下Android中插件开发篇的最后一篇文章的内容:动态加载Activity(免安装运行程序),在上一篇文章中说道了,如何动态加载资源(应用换肤原理解析 ...
- [转+补]Android打包so后魅族5中安装运行崩溃问题的解决方法
上周在做噪音检测so集成中,遇到不同的so库打包到 APK 时,安装在某些机器上,出现 java.lang.UnsatisfiedLinkError 加载失败. 为此,深究了一下原理,和给出了解决方案 ...
- SpringBoot(四)SpringBoot中lombok使用
lombok概述 lombok简介 Lombok想要解决了的是在我们实体Bean中大量的Getter/Setter方法,以及toString, hashCode等可能不会用到,但是某些时候仍然需要复写 ...
- springBoot中使用定时任务
简单示例 导入依赖 springBoot已经默认集成了定时任务的依赖,只需要引入基本的依赖就可以使用定时任务. <parent> <groupId>org.springfram ...
随机推荐
- iptables(四)iptables匹配条件总结之一
经过前文的总结,我们已经能够熟练的管理规则了,但是我们使用过的"匹配条件"少得可怜,之前的示例中,我们只使用过一种匹配条件,就是将"源地址"作为匹配条件. 那么 ...
- 【spark】RDD操作
RDD操作分为转换操作和行动操作. 对于RDD而言,每一次的转化操作都会产生不同的RDD,供一个操作使用. 我们每次转换得到的RDD是惰性求值的 也就是说,整个转换过程并不是会真正的去计算,而是只记录 ...
- 【河南省第十届ACM 省赛 A-谍报分析】
题目描述 “八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战.但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行. 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动 ...
- JAM计数法(模拟)
题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...
- 条款22:将成员变量声明为private
protected成员变量的封装性并非高于public变量. 如果有个public的成员变量,一旦其需要改变,那么所有使用它的代码都需要改变. 如果有个protected的成员变量,一点其需要改变,那 ...
- Mac os x 下配置Intellij IDEA + Tomcat 出现权限问题的解决办法
出现的错误提示如下: 下午9:11:27 All files are up-to-date下午9:11:27 All files are up-to-date下午9:11:27 Error runni ...
- js 复制粘贴功能记录
最近工作中需要在前端页面中使用代码完成剪贴板的读写,网上搜索了下相应的资料,记录下... 这个功能有两个办法一个是js方式,一个是使用flash 一.JS方法 1.复制 首先复制的过程分为两步曲,无论 ...
- SQLServer清空数据库中所有表的数据
今早同事跟进客户反馈的问题时,提了个要求,要求清空数据库中所有表的数据. 记得之前用游标遍历所有的表名 + exec 动态语句 truncate table 表名 实现过这个功能. 网上搜了下,有更简 ...
- test20181219(期末考试)
Written with StackEdit. \(noip\)爆炸后就好久没考试了...结果今天又被抓去,感觉很慌啊... 考完了.过来填坑. T1 Description 使得\(x^x\)达到或 ...
- Spring、Spring MVC、Struts2优缺点整理
Spring 及其优点 大部分项目都少不了Spring的身影,为什么大家对他如此青睐,而且对他的追捧丝毫没有减退之势呢 Spring是什么: Spring是一个轻量级的DI和AOP容器框架. 说它轻量 ...