安装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使用的更多相关文章

  1. activemq artemis安装运行及其在springboot中的使用

    安装 创建broker 在springboot中的使用 依赖 配置 Producer Consumer Rest使用 安装 http://activemq.apache.org/artemis/dow ...

  2. ActiveMQ第四弹:在HermesJMS中创建ActiveMQ Session

    Hermes JMS是一个开源免费的跨平台的JMS消息监听工具.它可以很方便和各种JMS框架集成和交互,可以用来监听.发送.接收.修改.存储消息等.这篇文章将讲解HermesJMS如何集成Active ...

  3. springboot之activemq安装与实践

    环境:腾讯云centos7 注意:activemq安装插件,可能会报错.本人是主机名的问题,所以修改了主机名. vim /etc/hosts vim /etc/hostname 修改这两个文件,并重启 ...

  4. 以ActiveMQ为例JAVA消息中间件学习【3】——SpringBoot中使用ActiveMQ

    前言 首先我们在java环境中使用了ActiveMQ,然后我们又在Spring中使用了ActiveMQ 本来这样已经可以了,但是最近SpringBoot也来了.所以在其中也需要使用试试. 可以提前透露 ...

  5. (二)Redis在Mac下的安装与SpringBoot中的配置

    1 下载Redis 官网下载,下载 stable 版本,稳定版本. 2 本地安装 解压:tar zxvf redis-6.0.1.tar.gz 移动到: sudo mv redis-6.0.1 /us ...

  6. Android中插件开发篇之----动态加载Activity(免安装运行程序)

    一.前言 又到周末了,时间过的很快,今天我们来看一下Android中插件开发篇的最后一篇文章的内容:动态加载Activity(免安装运行程序),在上一篇文章中说道了,如何动态加载资源(应用换肤原理解析 ...

  7. [转+补]Android打包so后魅族5中安装运行崩溃问题的解决方法

    上周在做噪音检测so集成中,遇到不同的so库打包到 APK 时,安装在某些机器上,出现 java.lang.UnsatisfiedLinkError 加载失败. 为此,深究了一下原理,和给出了解决方案 ...

  8. SpringBoot(四)SpringBoot中lombok使用

    lombok概述 lombok简介 Lombok想要解决了的是在我们实体Bean中大量的Getter/Setter方法,以及toString, hashCode等可能不会用到,但是某些时候仍然需要复写 ...

  9. springBoot中使用定时任务

    简单示例 导入依赖 springBoot已经默认集成了定时任务的依赖,只需要引入基本的依赖就可以使用定时任务. <parent> <groupId>org.springfram ...

随机推荐

  1. xlearn安装

    xlearn简介 xLearn is a high performance, easy-to-use, and scalable machine learning package, which can ...

  2. 在阿里云上安装python3.4和pycharm

    一. 安装python3.4 二. 安装pycharm 三. 安装可视化界面和远程桌面连接 四. 启动和配置pycharm 五. 安装更多字体 六. 给pycharm设置桌面快捷方式 一. 安装pyt ...

  3. grep 查询包含内容的文件

    加入到 ~/.bashrc 或者 ~/.bash_profile bash export GREPF_FILES=/mnt/d/Developer:/mnt/e/Developer function ...

  4. H5手机端按钮点击一次却触发了多次点击事件

    方案:在点击事件方法中加入以下语句 event.stopPropagation();

  5. Python正则表达式------进阶

    Python正则表达式 正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式. re ...

  6. HDU 3452 Bonsai(树形dp)

    Bonsai Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  7. spring 多数据源动态切换

    理解spring动态切换数据源,需要对spring具有一定的了解 工作中经常遇到读写分离,数据源切换的问题,那么以下是本作者实际工作中编写的代码  与大家分享一下! 1.定义注解 DataSource ...

  8. Today is weekend不是应该一定会输出吗

    判断语句 If…else块,请看下面这个例子: <%! int day = 3; %> //声明变量感叹号 <html> <head><title>IF ...

  9. Flask 上下文管理-- (session,request,current_app的传递)--类似本地线程实现,以及多app应用

    Flask session,request,current_app的传递 请求上下文的作用 -- 封装请求相关得数据(request,session) 请求上下文 request session re ...

  10. [置顶] Android RadioButton与TextView浪漫约会?

    情景一 今天主要实现一个国家与地区切换,就是当我们选中RadioButton时然后将值设置到TextView中,听着这需求应该不难对吧?那么我们就开始约会吧? 看下原型图 准备条件: 首先需要一个ra ...