1.配置pom相关依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
       <version>1.5.4.RELEASE</version>
     </dependency>

2.在application.yml配置文件下配置相关信息

 spring:          #表示该配置直接为Spring容器负责处理 
jms:
pub-sub-domain: false #配置消息的类型,如果是true则表示为topic消息,如果为false表示Queue消息
activemq:
user: admin #连接用户名
password: admin #连接密码
broker-url: tcp://0.0.0.0:61616 #消息组件的连接主机信息

3.创建消费者代码

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service; @Service
public class MessageConsumerService {
@JmsListener(destination = "mldn.msg.queue")
public void receiveMessage(String text) {//进行消息接收处理
System.err.println("接受消息"+text);
}
}

4.建立生产者代码

生产者接口:

public interface ImessageProducerService {
public void sendMessage(String msg);
}

生产者实现:

import javax.annotation.Resource;
import javax.jms.Queue; import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service; import cn.mldn.microboot.producer.ImessageProducerService;
@Service
public class MessageProducerServiceImpl implements ImessageProducerService {
@Resource
private JmsMessagingTemplate jmsMessagingTemplate;
@Resource
private Queue queue;
@Override
public void sendMessage(String msg) {
this.jmsMessagingTemplate.convertAndSend(this.queue,msg);; } }

5.建立测试类

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import cn.mldn.microboot.StartSpringBootMain;
import cn.mldn.microboot.producer.ImessageProducerService; @SpringBootTest(classes = StartSpringBootMain.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class TestActiveMQ {
@Resource
private ImessageProducerService messageProducer;
@Test
public void testSend() throws Exception{
for (int i = 0; i < 103; i++) {
this.messageProducer.sendMessage("mldn-"+i);
}
}
}

6.增加消息Queue的配置

import javax.jms.Queue;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms; @Configuration
@EnableJms
public class ActiveMQConfig {
@Bean
public Queue queue() {
return new ActiveMQQueue("mldn.msg.queue");
}
}

7.启动activemq的服务,该服务可自行下载,我这里下载了一个Windows版本的,直接启动就好。

8.登录activmq,http://localhost:8161/admin/,用户名密码采用默认的,admin、admin。也可以在activmq的配置文件配置用户

这样我们就成功登录。

最后进行测试,测试成功,查看activemq的Queues,成功接收消息

SpringBoot配置activemq消息队列的更多相关文章

  1. SpringBoot集成ActiveMq消息队列实现即时和延迟处理

    原文链接:https://blog.csdn.net/My_harbor/article/details/81328727 一.安装ActiveMq 具体安装步骤:自己谷歌去 二.新建springbo ...

  2. springboot中activeMQ消息队列的引入与使用(发送短信)

    1.引入pom依赖 <!--activemq--><dependency> <groupId>org.springframework.boot</groupI ...

  3. activemq消息队列的使用及应用docker部署常见问题及注意事项

    activemq消息队列的使用及应用docker部署常见问题及注意事项 docker用https://hub.docker.com/r/rmohr/activemq/配置在/data/docker/a ...

  4. JAVA的设计模式之观察者模式----结合ActiveMQ消息队列说明

    1----------------------观察者模式------------------------------ 观察者模式:定义对象间一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的 ...

  5. ActiveMQ消息队列从入门到实践(4)—使用Spring JMS收发消息

    Java消息服务(Java Message Service ,JMS)是一个Java标准,定义了使用消息代理的通用API .在JMS出现之前,每个消息代理都有私有的API,这就使得不同代理之间的消息代 ...

  6. ActiveMQ 消息队列服务

      1 ActiveMQ简介 1.1 ActiveMQ是什么 ActiveMQ是一个消息队列应用服务器(推送服务器).支持JMS规范. 1.1.1 JMS概述 全称:Java Message Serv ...

  7. ActiveMQ基础教程(四):.net core集成使用ActiveMQ消息队列

    接上一篇:ActiveMQ基础教程(三):C#连接使用ActiveMQ消息队列 这里继续说下.net core集成使用ActiveMQ.因为代码比较多,所以放到gitee上:https://gitee ...

  8. C#实现ActiveMQ消息队列

    本文使用C#实现ActiveMQ消息队列功能. 一.首先需要导入两个包,分别是:Apache.NMS 和 Apache.NMS.ActiveMQ 二.创建Winform程序实现生产者功能. 三.Pro ...

  9. SpringBoot学习笔记(11)-----SpringBoot中使用rabbitmq,activemq消息队列和rest服务的调用

    1. activemq 首先引入依赖 pom.xml文件 <dependency> <groupId>org.springframework.boot</groupId& ...

随机推荐

  1. electron开发客户端注意事项(兼开源个人知识管理工具“想学吗”)

    窗口间通信的问题 electron窗口通信比nwjs要麻烦的多 electron分主进程和渲染进程,渲染进程又分主窗口的渲染进程和子窗口的渲染进程 主窗口的渲染进程给子窗口的渲染进程发消息 subWi ...

  2. Writing a Simple Publisher and Subscriber

    用c++实现一个publisher/subscriber publisher #include "ros/ros.h" #include "std_msgs/String ...

  3. 浅谈Quartz.Net 从无到有创建实例

    一.Quartz.Net介绍 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等. Quartz.NET允许开发人员根据时间间隔(或 ...

  4. centOS7下Spark安装配置

    环境说明: 操作系统: centos7 64位 3台 centos7-1 192.168.190.130 master centos7-2 192.168.190.129 slave1 centos7 ...

  5. css选择器概述

    css选择器种类 id选择器 类选择器.属性选择器.伪类选择器 元素选择器.伪元素选择器 通配符选择器.子类选择器.后代选择器.相邻兄弟选择器.选择器分组 一.id选择器 <p id=" ...

  6. arcgis api 3.x for js 入门开发系列二十一气泡窗口信息动态配置模板

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  7. Android远程桌面助手(B1391)

    ARDC(B1391), Download:https://files.cnblogs.com/files/we-hjb/ARDC%28B1391%29_EN.7z Android远程桌面助手(B13 ...

  8. 2019-1-17 前言 C#高级编程(第11版)

    C#已更新为更快的速度.主要版本7.0是2017年3月发布,次要版本7.1和7.2很快发布在2017年8月和2017年12月.通过项目设置,您可以与每个应用程序一起分发,是开源的,不可用仅适用于Win ...

  9. The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.

    In one of our recent migrations, we got the following error when the client tried to fire xp_cmdshel ...

  10. EM算法(Expectation Maximization)

    1 极大似然估计     假设有如图1的X所示的抽取的n个学生某门课程的成绩,又知学生的成绩符合高斯分布f(x|μ,σ2),求学生的成绩最符合哪种高斯分布,即μ和σ2最优值是什么? 图1 学生成绩的分 ...