博客
关于我
SpringCloud之Stream整合RabbitMQ入门案例
阅读量:762 次
发布时间:2019-03-22

本文共 854 字,大约阅读时间需要 2 分钟。

Stream 概述

在这个项目中,我们采用Spring Cloud Stream框架,基于RabbitMQ作为消息中间件。通过选择适当的消息中间件组件,我们可以实现高效的微服务 communication。

基础

本项目基于Spring Cloud Stream框架,结合RabbitMQ实现消息队列功能。Spring Cloud Stream提供了一套简单易用的API,支持对消息中间件进行统一配置和管理。

hystrix-consumer 子工程

该子工程负责消费消息,集成了相关的Hystrix容错机制。项目结构包括以下几个关键部分: - pom文件配置了必要的依赖项,包括RabbitMQ相关的Spring Cloud Stream组件。 - 配置文件(application.yml)定义了消息的绑定器和绑定方法,确保消息能够按照预期的路由和格式接收。 - 监听器(MessageListener)类负责处理消息,实现消息的基本消费逻辑,适用于处理消息偏移或异常情况。

hystrix-provider 子工程

这个子项目主要负责消息生产,同样基于Spring Cloud Stream框架和RabbitMQ。项目结构包括: - pom文件类似hystrix-consumer部分,配置了相同的消息中间件组件。 - 配置文件定义了消息的发布渠道,包括消息的内容格式和目标交易号(test_exchange)。 - 生产者(MessageProducer)类负责构建并发布消息,支持消息的额外属性(如Endpoint)配置,支持集群发布。 - 控制器(GoodsController)提供了REST API接口,作为外部调用入口,负责消息的发布或调试。

测试

项目包含三个主要服务: 1. eureka-server 2. hystrix-consumer 3. hystrix-provider

通过自动化测试框架确保各组件的协同工作,确保消息能够顺利生产、传输、消费,并在出现故障时能够优雅降级。

转载地址:http://qgmwk.baihongyu.com/

你可能感兴趣的文章
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>