spring cloud stream集成rabbitmq
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的更多相关文章
- Spring Cloud Stream整合RabbitMQ
简介 Spring Cloud Stream是一个构建消息驱动微服务的框架,应用程序通过input(相当于consumer).output(相当于producer)来与Spring Cloud Str ...
- Spring Cloud Stream 整合 RabbitMQ
简介 Spring Cloud Stream是一个构建消息驱动微服务的框架,应用程序通过input(相当于consumer).output(相当于producer)来与Spring Cloud Str ...
- Spring Cloud Stream 使用延迟消息实现定时任务(RabbitMQ)
应用场景 通常在应用开发中我们会碰到定时任务的需求,比如未付款订单,超过一定时间后,系统自动取消订单并释放占有物品. 许多同学的第一反应就是通过spring的schedule定时任务轮询数据库来实现, ...
- 整合Spring Cloud Stream Binder与RabbitMQ进行消息发送与接收
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 前言 Spring Cloud Stream专门用于事件驱动的微服务系统,使用消息中间件来收发信息.使用Spring ...
- 【进阶技术】一篇文章搞掂:Spring Cloud Stream
本文总结自官方文档http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.0.RC3/single/spring-clou ...
- Spring Cloud Stream如何处理消息重复消费?
最近收到好几个类似的问题:使用Spring Cloud Stream操作RabbitMQ或Kafka的时候,出现消息重复消费的问题.通过沟通与排查下来主要还是用户对消费组的认识不够.其实,在之前的博文 ...
- Kafka及Spring Cloud Stream
安装 下载kafka http://mirrors.hust.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz kafka最为重要三个配置依次为:broke ...
- 这事没完,继续聊spring cloud stream和kafka的这些小事
上一篇文章讲了如何用spring cloud stream集成kafka,并且跑起来一个demo,如果这一次宣传spring cloud stream的文章,其实到这里就可以啦.但实际上,工程永远不是 ...
- 整合Spring Cloud Stream Binder与GCP Pubsub进行消息发送与接收
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 前言 之前的文章<整合Spring Cloud Stream Binder与RabbitMQ进行消息发送与接收& ...
随机推荐
- C#调取接口时报错:服务器提交了协议冲突. Section=ResponseStatusLine
private Dictionary<string, Object> GetLocation(string imei) { #region===代码=== string serviceAd ...
- Maven系列学习(一)Maven基本知识
Maven 简介 1.Maven主要是基于Java平台的项目构建,依赖管理和项目信息 2.Maven是优秀的构建工具,跨平台,消除构建的重复,抽象了一个完整的构建生命周期模型,标准化构建过程 3.管理 ...
- C++中使用CMake编译管理项目
CMake是一个跨平台的Makefile生成工具,可以根据特定的规则生成相应的Makefile文件,并对C/C++源代码进行编译和管理. 有一篇博客介绍CMake的使用,比较通俗易懂,链接地址是:Cm ...
- SpringBoot项目FatJar同War之间的相互转换
目录 1.原有的项目结构 修改后的项目结构 常见的dependency的scope 1.原有的项目结构 启动类 @SpringBootApplication(exclude = {DataSource ...
- python print (x,end = '') 意思作用
for x in range(10) python print(x)换行输出 for x in range(10) python print (x,end = '') 不换行输出
- ecshop 广告调用的几种方式
1,ECSHOP后台设置广告更换 前台调用 {insert name='ads' id=2 num=1} id值表达广告位置的id.num表示数量 2,在代码加函数 function getads($ ...
- Mybatis-技术专区-中的条件查询createCriteria example里面的条件
之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...
- C# 一个网站
http://www.aizhengli.com/aspnet-mvc5/6/aspnet-mvc5-member-user-register.html
- Python内置函数(19)-slice
官方文档 class slice(stop) class slice(start, stop[, step]) Return a slice object representing the set o ...
- Python 循环列表删除元素的注意事项
错误示范: class Solution: def removeElement(self, nums, val: int) -> int: for i, num in enumerate(num ...