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. Selenium+Java环境搭建

    1. 安装JDK URL:http://www.oracle.com/technetwork/java/javase/downloads/ 2. 配置环境变量 JAVA_HOME = E:\Java\ ...

  2. eclipse配置,快捷键备忘

    1. General --> Workspace --> UTF-82. General --> Editors --> Associations --> JSP --& ...

  3. inclusion_tag 基本使用

    inclusion_tag的用途 inclusion_tag可以实现从后台往前端传递绑定数据的样式,一般用来动态显示模板页面中显示固定格式的数据. inclusion_tag的用法 step1: 编写 ...

  4. 索引及explain

    索引好比书的目录.通过索引能快速的定位到一条数据. 在MySQL中除了B+树索引之外,还有一些其他的索引类型.比如:全文索引.(DB和DD索引叫R树索引).在MySQL cluster中是P树索引,m ...

  5. Docker配置远程访问

    近来学习Docker部署微服务,需要配置Docker的远程访问,由于实际环境和学习资料有出入,尝试着根据网上搜索的一些相关资料进行配置,未能成功.最终通过自己摸索,成功配置Docker远程访问.现和大 ...

  6. A AFei Loves Magic

    链接:https://ac.nowcoder.com/acm/contest/338/A来源:牛客网 题目描述 AFei is a trainee magician who likes to stud ...

  7. 图例演示在Linux上快速安装软RAID的详细步骤

    物理环境:虚拟机centos6.4 配置:8G内存.2*2核cpu.3块虚拟硬盘(sda,sdb,sdc,sdb和sdc是完全一样的)        在实际生产环境中,系统硬盘与数据库和应用是分开的, ...

  8. java随机数Math.random()

    double random=Math.random();//返回[0,1)随机数 (int)(Math.random()*6)//返回0-5:随机数 (int)(Math.random()*6+1)/ ...

  9. 2018-8-10-如何使用-Q#

    title author date CreateTime categories 如何使用 Q# lindexi 2018-08-10 19:16:51 +0800 2018-2-13 17:23:3 ...

  10. EAN13条码的校验位的Excel算法

    校验位原公式: 单元格=10-RIGHT(SUM(MID($B3,{1;2;3;4;5;6;7;8;9;10;11;12},1)*{1;3;1;3;1;3;1;3;1;3;1;3})) 简化公式: 单 ...