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 ...
随机推荐
- C#笔记之 函数可变参数
(转自:http://blog.csdn.net/jackluangle/article/details/6539278) 其实函数的参数的可变是因为不确定函数的参数大小的原因才使用的.看下面一个列子 ...
- 条款14:在资源管理类中小型coping的行为
首先假设对于一个mutex互斥器对象,有lock以及unlock两个函数可用: void lock(Mutex * pm); void unlock(Mutex * pm); 那么为了防止资源忘记被释 ...
- 【git】git知识梳理(一):基本操作&远程控制&分支管理
(一)基本操作: git中所有文件一共有三个状态:已提交,已暂存,已修改. 三个工作区域: git目录:.git文件夹,每次拷贝其实只拷贝git目录 工作目录:文件和目录都是从git目录中压缩对象数 ...
- Amazon 发送个人文档无回复
Amazon 个人文档问题 注意注意 详情见:[使用您的[发送至Kindle]电子邮箱] 重点提示 在电子邮件主题中输入"Convert"以将您的文档转换为Kindle格式,然后再 ...
- python 中出现 “IndentationError: expected an indented block” 问题
python 学习 在定义Python函数的时候如下 >>>def hello() . . .print "hello" 这样会报错的,报错如下: Indenta ...
- 让cocos h5里的文字可以在手机上被长按复制
更改CCBoot.js代码: // Adjust mobile css settings if (cc.sys.isMobile) { var fontStyle = document.createE ...
- Linq:Grouping Operators
[Category("Grouping Operators")] [Description("This sample uses group by to partition ...
- 转载 fpga中 restoring 和 non-restoring 除法实现。
对于non-restoring方法,主要是用rem和den移位数据比较,rem_d长度为den+nom的总长,den_d长度为den+nom的总长度,rem_d的初始值为{{d_width{1'b0} ...
- docker 命令记录
从 Docker 镜像仓库获取镜像的命令是 docker pull.其命令格式为: docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] 具体的选项 ...
- FastAdmin 将 PHP 框架升级到 ThinkPHP 5.1
FastAdmin 将 PHP 框架升级到 ThinkPHP 5.1 社区经常有人问什么时候升级到 ThinkPHP 5.1,但是 ThinkPHP 5.1 和 ThinkPHP 5.0 差别非常大, ...