#yyds干货盘点# springcloud整合stream,rabbitmq实现消息驱动功能
Posted 灰太狼_cxh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#yyds干货盘点# springcloud整合stream,rabbitmq实现消息驱动功能相关的知识,希望对你有一定的参考价值。
springcloud整合stream,rabbitmq实现消息驱动功能
1.代码实现:
创建项目stream
添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cxh</groupId>
<artifactId>stream</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>stream</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
<spring-cloud-alibaba-dependencies.version>2021.1</spring-cloud-alibaba-dependencies.version>
<spring-cloud-dependencies.version>2021.0.0</spring-cloud-dependencies.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>$spring-cloud-dependencies.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>$spring-cloud-alibaba-dependencies.version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
</dependencies>
监听类
@EnableBinding(Sink.class)
public class SinkReceiver
private static Logger logger = LoggerFactory.getLogger(SinkReceiver.class);
@StreamListener(Sink.INPUT)
public void receive(String payload)
logger.info("Received: " + payload);
2.实现效果:
启动rabbitmq, 项目stream
打开浏览器http://localhost:15672/,使用账号密码guest登录rabbitmq, 在队列中发现消息:
测试send
查看控制台消息:
com.cxh.stream.SinkReceiver : Received: 测试send
以上是关于#yyds干货盘点# springcloud整合stream,rabbitmq实现消息驱动功能的主要内容,如果未能解决你的问题,请参考以下文章
#yyds干货盘点# springcloud整合gateway实现网关全局过滤器功能
#yyds干货盘点# springcloud整合stream实现同一通道根据消息内容分发不同的消费逻辑
#yyds干货盘点# springcloud整合ribbon实现服务负载均衡
#yyds干货盘点# springcloud整合eureka实现服务注册与发现