pom添加依赖

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>

application.yml配置

# Spring 相关
spring:
# rabbitmq
rabbitmq:
host: 192.168.3.107
port: 5672
username: admin
password: 123456

定义输入通道

package com.zh.common.api.rabbitmq;

import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel; /**
* @Auther: suruozhong
* @Date: 2019/9/17 15:45
* @Description:
*/
public interface OrderChannel {
//定义通道的名称
String saveOrder = "saveOrder";
//定义为输入通道
@Input(saveOrder)
SubscribableChannel saveOrder(); }

定义输出通道

package com.zh.common.api.rabbitmq;

import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel; /**
* @Auther: suruozhong
* @Date: 2019/9/17 15:51
* @Description:
*/
public interface OrderOutputChannel { //定义通道的名称
String saveOrder = "saveOrder";
//定义为输入通道
@Output(saveOrder)
MessageChannel saveOrder(); }

生产端

在对应的模块绑定输入通道

/**
* @Auther: suruozhong
* @Date: 2019/7/24 15:51
* @Description:
*/
@SpringCloudApplication
@EnableAutoConfiguration(exclude = {
SecurityAutoConfiguration.class
})
//通过绑定器对OderChannel通道进行绑定
@EnableBinding(OrderOutputChannel.class)
public class HousekeeperFrontApplication { public static void main(String[] args) {
SpringApplication.run(HousekeeperFrontApplication.class,args);
}
}

发送消息

@RestController
@RequestMapping("/sysBanner")
public class SysBannerController { @Resource
private OrderOutputChannel orderOutputChannel; @RequestMapping(value = "/list")
public void listData(String position) {
orderOutputChannel.saveOrder().send(MessageBuilder.withPayload("fff").build());
} }

消费端

在对应的模块绑定输出通道

/**
* @author
* @date 2018年06月21日
* 用户统一管理系统
*/
@SpringCloudApplication
@EnableScheduling //开启定时任务
//通过绑定器对OderChannel通道进行绑定
@EnableBinding(OrderChannel.class)
public class HousekeeperAdminApplication {
public static void main(String[] args) {
SpringApplication.run(HousekeeperAdminApplication.class, args);
} }

绑定监听消息

@Service("sysBannerService")
@Transactional
public class SysBannerServiceImpl extends ServiceImpl<SysBannerMapper, SysBanner> implements SysBannerService { //对saveOrder的消息监听处理
@StreamListener(OrderChannel.saveOrder)
private void receiver(Object message){
System.out.println(message.toString());
}

分组加持久化配置

在生产端的application.yml

spring:
cloud:
# spring cloud strem
stream:
bindings:
saveOrder: 输出通道名称
group: saveOrder 分组名称

spring cloud stream集成rabbitmq的更多相关文章

  1. Spring Cloud Stream整合RabbitMQ

    简介 Spring Cloud Stream是一个构建消息驱动微服务的框架,应用程序通过input(相当于consumer).output(相当于producer)来与Spring Cloud Str ...

  2. Spring Cloud Stream 整合 RabbitMQ

    简介 Spring Cloud Stream是一个构建消息驱动微服务的框架,应用程序通过input(相当于consumer).output(相当于producer)来与Spring Cloud Str ...

  3. Spring Cloud Stream 使用延迟消息实现定时任务(RabbitMQ)

    应用场景 通常在应用开发中我们会碰到定时任务的需求,比如未付款订单,超过一定时间后,系统自动取消订单并释放占有物品. 许多同学的第一反应就是通过spring的schedule定时任务轮询数据库来实现, ...

  4. 整合Spring Cloud Stream Binder与RabbitMQ进行消息发送与接收

    我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 前言 Spring Cloud Stream专门用于事件驱动的微服务系统,使用消息中间件来收发信息.使用Spring ...

  5. 【进阶技术】一篇文章搞掂:Spring Cloud Stream

    本文总结自官方文档http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.0.RC3/single/spring-clou ...

  6. Spring Cloud Stream如何处理消息重复消费?

    最近收到好几个类似的问题:使用Spring Cloud Stream操作RabbitMQ或Kafka的时候,出现消息重复消费的问题.通过沟通与排查下来主要还是用户对消费组的认识不够.其实,在之前的博文 ...

  7. Kafka及Spring Cloud Stream

    安装 下载kafka http://mirrors.hust.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz kafka最为重要三个配置依次为:broke ...

  8. 这事没完,继续聊spring cloud stream和kafka的这些小事

    上一篇文章讲了如何用spring cloud stream集成kafka,并且跑起来一个demo,如果这一次宣传spring cloud stream的文章,其实到这里就可以啦.但实际上,工程永远不是 ...

  9. 整合Spring Cloud Stream Binder与GCP Pubsub进行消息发送与接收

    我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 前言 之前的文章<整合Spring Cloud Stream Binder与RabbitMQ进行消息发送与接收& ...

随机推荐

  1. CodeForces 219D Choosing Capital for Treeland (树形DP)经典

    <题目链接> 题目大意: 给定一个有向树,现在要你从这颗树上选一个点,使得从这个点出发,到达树上其它所有点所需翻转的边数最小,输出最少需要翻转的边数,并且将这些符合条件的点输出. 解题分析 ...

  2. 如何在linux命令行无界面下使用selenium

    1.安装Xvfb和pyvirtualdisplay sudo apt-get install xvfbpip install pyvirtualdisplay 2.安装chrome, chromedr ...

  3. 烂漫爱心表白动画 分类: C# 2014-10-07 19:08 28人阅读 评论(0) 收藏

    曾经我说过我会用程序来表达我对你的爱. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  4. Js数据去重复,时间更换格式,cookie,localStorage和sessionStorage的使用等通用方法

    一,数组去重复 function unique(arr) { // 遍历arr,把元素分别放入tmp数组(不存在才放) var tmp = new Array(); for (var i in arr ...

  5. BUUCTF--xor

    测试文件:https://buuoj.cn/files/caa0fdad8f67a3115e11dc722bb9bba7/7ea34089-68ff-4bb7-8e96-92094285dfe9.zi ...

  6. 攻防世界--getit

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/8ef2f7ef55c240418f84b3c514a7a28a 准备 得知 64位文件 ...

  7. 分析abex'crackme#2

    文件地址:https://www.wocloud.com.cn/webclient/share/sindex.action?id=i9K_Br6TgE4gbyGIlYkffWKcRy5TUdZ8U6_ ...

  8. CSS世界中的“盒子”

    1.块级元素 HTML标签通常被分为两类:块级元素和内联元素. “块级元素”和“display为block的元素”不是同一个概念.例如<li>元素默认的display值为list-item ...

  9. 关于正则表达式RegExp

    常用元字符串 元字符 说明 \d 匹配   数字 \D 匹配   非数字 \w 匹配   数字,字母,下划线 \W 匹配   任意不是字母,数字,下划线 \s 匹配   空白符 \S 匹配   任意不 ...

  10. DOM IE 兼容性 I

    IE8事件模型和DOM事件模型有何不同?如何处理DOM事件模型与IE8事件模型的兼容性? 1 事件模型不一样 DOM的浏览器兼容性问题:事件模型   3个阶段            01 外向内:捕获 ...