安装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. python:一个比较有趣的脚本

    宿舍火星wifi经常掉,然后要重启,于是用Python写了一个脚本,用来远程控制火星wifi的重启 思路: 01.使用socket通讯 02.在wifi主机(开wifi的电脑)上运行客户端,控制机运行 ...

  2. C/C++开发android应用

    (转自:http://blog.csdn.net/srplab1/article/details/7617963) 在某些情况下,比如原来与很多c/c++的代码, 可能希望采用c/c++编写andro ...

  3. python基础之模块一

    一 time模块 时间表示形式 在Python中,通常有这三种方式来表示时间:时间戳.元组(struct_time).格式化的时间字符串:(1)时间戳(timestamp) :通常来说,时间戳表示的是 ...

  4. Java并发编程总结

    基础概念 1.什么是原子操作?在Java Concurrency API中有哪些原子类(atomic classes)?原子操作(atomic operation)意为"不可被中断的一个或一 ...

  5. Android面试题整理

    1.    请描述下Activity的生命周期. 2.    如果后台的Activity由于某原因被系统回收了,如何在被系统回收之前保存当前状态? 3.    如何将一个Activity设置成窗口的样 ...

  6. Android学习之Activity跳转与传值

    Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一 Intent intent = new Intent(A.this, ...

  7. => 应用在js回调函数中

    => 可以简化以前的回调函数的调用,具体来说: 今后,几乎所有的回调函数都可用箭头函数简化 比如: 1. 所有回调函数都可: 去function改=> 2. 如果函数体只有一句话: 可省略 ...

  8. c++ 霍夫变换检测直线

    通常这是一幅边缘图像,比如来自 Canny算子.cv:: Houghlines函数的输出是cV::Vec2f向量,每个元素都是一对代表检测到的直线的浮点数(p,0).在下例中我们首先应用 Canny算 ...

  9. golang包快速生成base64验证码

    base64Captcha快速生成base64编码图片验证码字符串 支持多种样式,算术,数字,字母,混合模式,语音模式. Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一.Base6 ...

  10. 也谈TDD,以及三层架构、设计模式、ORM……没有免费的午餐,选择了,必付出代价

    想在园子里写点东西已经很久了,但一直没有落笔,忙着做 一起帮 的开发直播,还有些软文做推广,还要做奶爸带孩子,还要……好吧,我承认,真正的原因是: 太特么的难写了! 但再难写也要写啊,要等到“能写好了 ...