Rabbitmq 与springboot 结合
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
2.yml
spring:
application:
name: spring-boot-rabbitmq-sender
rabbitmq:
host: 127.0.0.1
port: 5672
username: mm
password: 123
virtual-host: /test
3.
AmqpAdmin 创建组件:如交换机,队列,绑定队则
RabbitTemplate:发送,接受消息
package com.aynu.bootamqp; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest
public class BootamqpApplicationTests { @Autowired
RabbitTemplate rabbitTemplate;
@Autowired
AmqpAdmin amqpAdmin; @Test
public void create(){
Exchange exchange = new DirectExchange("test22222",true,false);
amqpAdmin.declareExchange(exchange);
System.out.println("创建成功"); Queue queue = new Queue("999",true);
amqpAdmin.declareQueue(queue); Binding binding = new Binding("999", Binding.DestinationType.QUEUE,"test22222","goods.add",null);
amqpAdmin.declareBinding(binding);
} @Test
public void contextLoads(){
String msg ="hello msg";
rabbitTemplate.convertAndSend("test22222","goods.add",msg);
}
@Test
public void receive(){
Object o = rabbitTemplate.receiveAndConvert("999");
System.out.println(o);
} }
4. 开启队列监控
@Test
@RabbitListener(queues = "999")
public void receive1(){
System.out.println();
}
@EnableRabbit
@RunWith(SpringRunner.class)
@SpringBootTest
public class BootamqpApplicationTests {}
Rabbitmq 与springboot 结合的更多相关文章
- RabbitMQ和SpringBoot的简单整合列子
一 思路总结 1 主要用spring-boot-starter-amqp来整合RabbitMQ和SpringBoot 2 使用spring-boot-starter-test来进行单元测试 3编写配置 ...
- 消息中间件——RabbitMQ(十)RabbitMQ整合SpringBoot实战!(全)
前言 1. SpringBoot整合配置详解 publisher-confirms,实现一个监听器用于监听Broker端给我们返回的确认请求:RabbitTemplate.ConfirmCallbac ...
- RabbitMQ与SpringBoot整合
RabbitMQ SpringBoot 一.RabbitMQ的介绍 二.Direct模式 三.Topic转发模式 四.Fanout Exchange形式 原文地址: https://www.cnb ...
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
- SpringBoot28 RabbitMQ知识点、Docker下载RabbitMQ、SpringBoot整合RabbtiMQ
1 RabbitMQ知识点 1.1 整体架构图 消息生产者将消息投递到exchange中,exchange会以某种路由机制将生产者投递的消息路由到queue中,消息消费者再从queue中获取消息进行消 ...
- 02.RabbitMQ整合springboot简单使用
1.添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- rabbitMQ结合spring-boot使用(1)
从这一节开始我们进入rabbitMQ的实战环节,项目环境是spring-boot 加maven.首先让我们创建一个spring-boot项目,然后引入web依赖和 rabbitMQ的依赖 <de ...
- RabbitMQ从概念到使用、从Docker安装到RabbitMQ整合Springboot【1.5w字保姆级教学】
@ 目录 一.前言 二.RabbitMQ作用 1. 异步处理 2. 应用解耦 3. 流量控制 三.RabbitMQ概念 1. RabbitMQ简介 2. 核心概念 四.JMS与AMQP比较 五.Rab ...
- 案例源码解读及思路:RabbitMQ在springboot中的配置
程序员的高级之处不是什么都会,而是对自己不会的进行抽象,然后完成自己的工作.比如对于RabbitMQ,按照字面理解,就将其看成Message Queue,也就是用来容纳对象的集合.很多功能都拆分给一个 ...
随机推荐
- postman接口测试基础知识
接口文档访问地址:http://doc.nnzhp.cn/index.php?s=/6&page_id=8 1.什么是接口:从数据库里面取数据或是插入数据 接口测试:测接口一定要有接口文档-- ...
- RHEL 6 和 RHEL 7 的一些有关运行级别,服务管理,服务启动等方面的区别介绍
systemd是7中的新命令组,集成了service和chkconfig的功能.system命令可参考:https://www.cnblogs.com/ray-bk/p/10415173.html 运 ...
- Hadoop学习笔记02_MapReduce练习
搭建好环境之后 ,就来跑个简单的Mapreduce试试看吧.这个比第一课难多了,需要多多练习并熟练掌握. 需要编写py脚本以及shell脚本, 所以需要学习Python和Linux的Shell编程. ...
- fiddler之数据统计(statistics)
在使用fiddler代理监听访问时,可以使用statistics分页去统计请求和响应的一些信息. 界面显示如下: 可以在这里查看一个session的统计信息 说明: 1.request count:请 ...
- repeter 控制一行中显示几条内容
repeter 控制一行中显示几条内容 <asp:Repeater ID="Repeater1" runat="server" DataSourceID ...
- ubuntu16.04下python2、python3环境选择与python升级(pip版本切换)
参考链接:https://www.jianshu.com/p/63c1f22e1fed Ubuntu中python版本问题: 添加PPA: sudo add-apt-repository ppa:jo ...
- 剑指Offer 35. 数组中的逆序对 (数组)
题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%1000 ...
- JAVA高级篇(一、JVM基本概念)
一.什么是JVM VM的中文名称叫Java虚拟机,它是由软件技术模拟出计算机运行的一个虚拟的计算机. JVM也充当着一个翻译官的角色,我们编写出的Java程序,是不能够被操作系统所直接识别的,这时候J ...
- crm --- 1.admin , 展示列表 和 分页
一.admin (创建超级用户) 1.注册: 1.创建一个超级管理员,使用如下命令: python manage.py createsuperuser 2.输入打算使用的登录名: username:m ...
- Vue 表单校验 vee-validate
gitHub 地址:https://github.com/baianat/vee-validate 官网API 地址:https://baianat.github.io/vee-validate/ap ...