安装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. iptables(三)iptables规则管理(增、删、改)

    上一篇文章中,我们已经学会了怎样使用iptables命令查看规则,那么这篇文章我们就来总结一下,怎样管理规则. 之前,我们把查看iptables规则的操作比作"增删改查"当中的&q ...

  2. java环信服务端注册IM代码

    下载环信api代码 https://github.com/easemob/emchat-server-examples 里面包含各种语言版本,我只下载了java版emchat-server-java ...

  3. MySQL密码过期

    1.用mysql命令行登录mysql的root用户 2.重新修改root密码 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); my ...

  4. Photoshop脚本指南——Hello World

    作为一个程序猿,每一个东西的学习都是从Hello World开始的,从今天开始,让我们一起进入Photoshop脚本的世界,并以Hello World开始我们的旅程. 1.简介 Photoshop支持 ...

  5. 小晚wan的公众号

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70932630 本文出自[我是干勾鱼的博客] 小晚wan的公众号还是挺深刻的,有时 ...

  6. H5 pattern

    pattern:正则表达式验证 例如: <input pattern="1[3578]\d{9}">  可以省略^和$ 必须和required配合使用,否则在用户没有输 ...

  7. So sad! ,Asphyre Closure

    So sad ! Asphyre Closure! 不过我相信开发App用Delphi应该是快的. 越与平台无关,优势越明显. 积累的组件市场. 虽然objc 有很多开源支持. 但总感觉还不够delp ...

  8. [QT][问题]关于QT语言家使用失败的原因之一

    按照标准的qt使用教程 ( http://www.qter.org/forum.php?mod=viewthread&tid=781 ) 实践了下,发现除去主界面外,点开的窗口多语言没有问题. ...

  9. RabbitMQ学习系列二-C#代码发送消息

    RabbitMQ学习系列二:.net 环境下 C#代码使用 RabbitMQ 消息队列 http://www.80iter.com/blog/1437455520862503 上一篇已经讲了Rabbi ...

  10. 【BZOJ2908】又是nand 树链剖分+线段树

    [BZOJ2908]又是nand escription 首先知道A nand B=not(A and B) (运算操作限制了数位位数为K)比如2 nand 3,K=3,则2 nand 3=not (2 ...