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,也就是用来容纳对象的集合.很多功能都拆分给一个 ...
随机推荐
- Kafka0.8.2删除topic逻辑(转)
原文链接:Kafka0.8.2.1删除topic逻辑 前提条件: 在启动broker时候开启删除topic的开关,即在server.properties中添加: delete.topic.enabl ...
- binary and out mode to open a file
When I use binary and out mode to open a exist file, and to modify the 4th and 8th byte data to 0x78 ...
- 将GETDATE()转换为指定日期格式的varchar类型
CREATE FUNCTION [dbo].[FormatDate] (@date as datetime, ) ) ) AS BEGIN ) set @datestring=@formatstrin ...
- enctype="multipart/form-data"表单传值问题
问题: form表单的enctype设置为multipart/form-data后,表单中除了文件后台能拿到,其他值后台都拿不到. 知识点: 一.application/x-www-form-urle ...
- jQuery-3.事件篇---鼠标事件
jQuery鼠标事件之click与dbclick事件 用交互操作中,最简单直接的操作就是点击操作.jQuery提供了两个方法一个是click方法用于监听用户单击操作,另一个方法是dbclick方法用于 ...
- #20175120彭宇辰 java第四周总结
教材学习内容总结 -第五章 子类与继承 子类的定义-class 子类名 extends 父类名ps:-任何类都是object的子类-每个类有且仅有一个父类,多个或0个子类 同一包里的继承性-除了pri ...
- echarts画饼环状饼图相关参数配置
今天做页面的时候用到了环状饼图,大家都知道echarts的API文档看起来实在费劲,折腾了半天才画出来我想要的饼图,把我用到的参数配置分享给大家,希望能帮到和我一样的对echarts不是那么熟悉的童鞋 ...
- https原理及其中所包含的对称加密、非对称加密、数字证书、数字签名
声明:本文章已授权公众号Hollis转载,如需转载请标明转载自https://www.cnblogs.com/wutianqi/p/10654245.html(安静的boy) 一.为什么要使用http ...
- C# Android 开发中使用 Sqlite.NET ORM
开发环境:VS2015 Xamarin Sqlite.NET ORM 不就相当于 Entiry Framework For Xamarin 吗? 相当于用 C# 开发安卓程序访问 Sqlite 可以使 ...
- 什么是web前端开发?
Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/Flash等各种Web技术进行客户端产品的开发.完成客户端程序(也就是浏览器端)的开发,开发JavaScript以及F ...