<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 结合的更多相关文章

  1. RabbitMQ和SpringBoot的简单整合列子

    一 思路总结 1 主要用spring-boot-starter-amqp来整合RabbitMQ和SpringBoot 2 使用spring-boot-starter-test来进行单元测试 3编写配置 ...

  2. 消息中间件——RabbitMQ(十)RabbitMQ整合SpringBoot实战!(全)

    前言 1. SpringBoot整合配置详解 publisher-confirms,实现一个监听器用于监听Broker端给我们返回的确认请求:RabbitTemplate.ConfirmCallbac ...

  3. RabbitMQ与SpringBoot整合

    RabbitMQ  SpringBoot  一.RabbitMQ的介绍 二.Direct模式 三.Topic转发模式 四.Fanout Exchange形式 原文地址: https://www.cnb ...

  4. SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...

  5. SpringBoot28 RabbitMQ知识点、Docker下载RabbitMQ、SpringBoot整合RabbtiMQ

    1 RabbitMQ知识点 1.1 整体架构图 消息生产者将消息投递到exchange中,exchange会以某种路由机制将生产者投递的消息路由到queue中,消息消费者再从queue中获取消息进行消 ...

  6. 02.RabbitMQ整合springboot简单使用

    1.添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  7. rabbitMQ结合spring-boot使用(1)

    从这一节开始我们进入rabbitMQ的实战环节,项目环境是spring-boot 加maven.首先让我们创建一个spring-boot项目,然后引入web依赖和 rabbitMQ的依赖 <de ...

  8. RabbitMQ从概念到使用、从Docker安装到RabbitMQ整合Springboot【1.5w字保姆级教学】

    @ 目录 一.前言 二.RabbitMQ作用 1. 异步处理 2. 应用解耦 3. 流量控制 三.RabbitMQ概念 1. RabbitMQ简介 2. 核心概念 四.JMS与AMQP比较 五.Rab ...

  9. 案例源码解读及思路:RabbitMQ在springboot中的配置

    程序员的高级之处不是什么都会,而是对自己不会的进行抽象,然后完成自己的工作.比如对于RabbitMQ,按照字面理解,就将其看成Message Queue,也就是用来容纳对象的集合.很多功能都拆分给一个 ...

随机推荐

  1. wed

    先有一个无后缀的flag 文件 第一次改成 TXT 收索FLAG 得到了一段 flag.txt f返回到第一次修改后缀 改成RAR 打开RAR 发现一个 flag.txt 的文件 打开,即得到 fla ...

  2. python的format格式化

    使用方法:  '{}bbccc'.format(aa) = aabbcc, 用来代替python2中的%,即替换. 1.通过位置来指定替换 In [2]: '{0},{1}'.format('a', ...

  3. C++中多维数组传递参数

    在c++自定义函数时我们有时需要传递参数,有时以多维数组作为参数,这里就遇到了多维数组该怎么传值的问题了,首先我们看看一维数组是怎么做的. void print_num(int num[], int ...

  4. flask中自定义过滤器

    第一种方法: 1,第一步:自定义过滤器函数 # 自定义一个函数,将list里面的数据进行排序 def list_sort(list) return list.sort() 2.第二步:注册过滤器 第一 ...

  5. XXS level9

    (1)查看PHP源代码 <?php ini_set("display_errors", 0); $str = strtolower($_GET["keyword&q ...

  6. linux shell 指令搜索顺序

    在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的命令. 2.关键字,如if, ...

  7. 2018.4.24 快排查找第K大

    import java.util.Arrays; /* 核心思想:利用快排思想,先假定从大到小排序,找枢纽,枢纽会把大小分开它的两边,当枢纽下标等于k时, 即分了k位在它左边或右边,也就是最大或最小的 ...

  8. C++对象的构造、析构与拷贝构造

    今天下午在研究虚函数的时候遇到了一个问题,觉得很有意思,记录一下. 先看代码: class Base { public: Base(int value) { m_nValue = value; cou ...

  9. centos查看系统版本信息

    1.查看版本文件名称 ll /etc/*centos* 2.显示系统版本号 cat /etc/centos-release

  10. 时钟分组的用法---Clock Groups

    时钟分组的用法---Clock Groups 哪些时钟互相之间需要分组 同步时钟: 异步时钟: 不确定的时钟: 即使是从同一个MMCMs出来的时钟,有可能为不确定关系的时钟,如果它们之间的相位没有一个 ...