1.说明

在平台中使用了 spring stream 来集成消息队列服务,他的好处在于,屏蔽了代码的区别,只需要修改配置就可以完成消息的集成。平台目前支持 rabbit 和 rocketmq

2.在平台中切换消息队列

2.1 切换RABBITMQ

2.1.1 修改所有的 pom.xml

将队列的maven包修改为

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

2.1.2 修改 nacos-config-dev.properties

spring.cloud.stream.binders.local_rabbit.type= rabbit
spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.host=192.168.1.10
spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.port=5672
spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.username=admin
spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.password=admin
spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.virtual-host= /


# 日志输出
spring.cloud.stream.bindings.logOutput.destination=log
spring.cloud.stream.bindings.logOutput.group= log-group
spring.cloud.stream.bindings.logOutput.binder = local_rabbit

# API日志输出队列
spring.cloud.stream.bindings.apiLogOut.destination=apilog
spring.cloud.stream.bindings.apiLogOut.group= apilog-group
spring.cloud.stream.bindings.apiLogOut.binder = local_rabbit
# 出错日志记录
spring.cloud.stream.bindings.errLogOut.destination=errlog
spring.cloud.stream.bindings.errLogOut.group= errlog-group
spring.cloud.stream.bindings.errLogOut.binder = local_rabbit

2.1.3 修改 nacos 关于 jpaas-bpm-dev.properties

# 系统消息
spring.cloud.stream.bindings.msgOutput.destination=bpmmessage
spring.cloud.stream.bindings.msgOutput.group= bpmmessage-group
spring.cloud.stream.bindings.msgOutput.binder = local_rabbit


# 流程异步事件
spring.cloud.stream.bindings.eventOutput.destination=event
spring.cloud.stream.bindings.eventOutput.group= event-group
spring.cloud.stream.bindings.eventOutput.binder = local_rabbit
spring.cloud.stream.bindings.eventInput.destination= event
spring.cloud.stream.bindings.eventInput.group= event-group-consumer
spring.cloud.stream.bindings.eventInput.binder = local_rabbit

2.1.4 修改 nacos 关于 jpaas-user-dev.properties

# 邮件消息
spring.cloud.stream.bindings.mailOutput.destination=mail
spring.cloud.stream.bindings.mailOutput.group= mail-group
spring.cloud.stream.bindings.mailOutput.binder = local_rabbit
spring.cloud.stream.bindings.mailInput.destination= mail
spring.cloud.stream.bindings.mailInput.group= mail-group-consumer
spring.cloud.stream.bindings.mailInput.binder = local_rabbit

2.1.4 修改 nacos 关于 jpaas-system-dev.properties


spring.cloud.stream.bindings.msgInput.destination= jpaas-message
spring.cloud.stream.bindings.msgInput.group= jpaas-message-group-consumer
spring.cloud.stream.bindings.msgInput.binder = local_rabbit

# 附件转换消息
spring.cloud.stream.bindings.fileOutput.destination=file
spring.cloud.stream.bindings.fileOutput.group= file-group
spring.cloud.stream.bindings.fileOutput.binder = local_rabbit

spring.cloud.stream.bindings.fileInput.destination= file
spring.cloud.stream.bindings.fileInput.group= file-group-consumer
spring.cloud.stream.bindings.fileInput.binder = local_rabbit

# 日志接收消息
spring.cloud.stream.bindings.logInput.destination= log
spring.cloud.stream.bindings.logInput.group= log-group-consumer
spring.cloud.stream.bindings.logInput.binder = local_rabbit

# API日志消费队列
spring.cloud.stream.bindings.apiLogInput.destination= apilog
spring.cloud.stream.bindings.apiLogInput.group= apilog-group-consumer
spring.cloud.stream.bindings.apiLogInput.binder = local_rabbit

spring.cloud.stream.bindings.errLogInput.destination= errlog
spring.cloud.stream.bindings.errLogInput.group= errlog-group-consumer
spring.cloud.stream.bindings.errLogInput.binder = local_rabbit

2.2 切换到ROCKETMQ

2.2.1 修改所有的pom.xml

将队列的maven包引用修改为

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-stream-binder-rocketmq</artifactId>
</dependency>

2.2.2 nacos-config-dev.properties

# rocketmq 
spring.cloud.stream.rocketmq.binder.name-server=192.168.1.10:9876

# 日志输出
spring.cloud.stream.bindings.logOutput.destination=log
spring.cloud.stream.bindings.logOutput.group= log-group


# API日志输出队列
spring.cloud.stream.bindings.apiLogOut.destination=apilog
spring.cloud.stream.bindings.apiLogOut.group= apilog-group

# 出错日志记录
spring.cloud.stream.bindings.errLogOut.destination=errlog
spring.cloud.stream.bindings.errLogOut.group= errlog-group

如果rocketmq 部署了集群,那么 这个 name-server 可以部署多台。

配置的时候使用 ;隔开 例如 192.168.1.10:9876;192.168.1.11:9876

2.2.3 nacos jpaas-bpm-dev.properties

# ROCKETMQ系统消息
spring.cloud.stream.bindings.msgOutput.destination=bpmmessage
spring.cloud.stream.bindings.msgOutput.group= bpmmessage-group


# 流程异步事件
spring.cloud.stream.bindings.eventOutput.destination=event
spring.cloud.stream.bindings.eventOutput.group= event-group
spring.cloud.stream.bindings.eventInput.destination= event
spring.cloud.stream.bindings.eventInput.group= event-group-consumer

2.2.4 修改 nacos 关于 jpaas-user-dev.properties

# 邮件收发队列
spring.cloud.stream.bindings.mailOutput.destination=mail
spring.cloud.stream.bindings.mailOutput.group= mail-group
spring.cloud.stream.bindings.mailInput.destination= mail
spring.cloud.stream.bindings.mailInput.group= mail-group-consumer

2.2.5 修改 nacos 关于 jpaas-system-dev.properties

# 流程消息接收
spring.cloud.stream.bindings.msgInput.destination= jpaas-message
spring.cloud.stream.bindings.msgInput.group= jpaas-message-group-consumer

# 附件转换队列
spring.cloud.stream.bindings.fileOutput.destination=file
spring.cloud.stream.bindings.fileOutput.group= file-group
spring.cloud.stream.bindings.fileInput.destination= file
spring.cloud.stream.bindings.fileInput.group= file-group-consumer

3.切换到KAFKA

2.2.1 修改所有的pom.xml

将队列的maven包引用修改为

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

总共有三处需要调整

  1. 日志模块
  2. 消息模块
  3. share模块

2.2.2 修改 nacos-config-dev.properties 配置

修改kafka 的配置

#配置kafka 消息服务器
spring.cloud.stream.kafka.binder.brokers= localhost:9092
spring.cloud.stream.bindings.output.contentType=text/plain
spring.cloud.stream.bindings.input.contentType=text/plain
# 日志输出
spring.cloud.stream.bindings.logOutput.destination=log
# 流程消息
spring.cloud.stream.bindings.msgOutput.destination= jpaas-message

# API日志输出队列
spring.cloud.stream.bindings.apiLogOut.destination= apilog
# 错误队列输出配置
spring.cloud.stream.bindings.errLogOut.destination= errlog

2.2.3 修改 jpaas-bpm-dev.properties

## 流程异步事件,这个消息时负责发送流程异步事件
spring.cloud.stream.bindings.eventOutput.destination=event
spring.cloud.stream.bindings.eventInput.destination= event
spring.cloud.stream.bindings.eventInput.group= event-group-consumer

2.2.4 修改 jpaas-system-dev.properties

## 附件转换消息
spring.cloud.stream.bindings.fileOutput.destination=file
spring.cloud.stream.bindings.fileInput.destination= file
spring.cloud.stream.bindings.fileInput.group= file-group-consumer

# 日志消费队列
spring.cloud.stream.bindings.logInput.destination= log
spring.cloud.stream.bindings.logInput.group= log-group-consumer

# API日志消费队列
spring.cloud.stream.bindings.apiLogInput.destination= apilog
spring.cloud.stream.bindings.apiLogInput.group= apilog-group-consumer
# 错误日志消费队列
spring.cloud.stream.bindings.errLogInput.destination= errlog
spring.cloud.stream.bindings.errLogInput.group= errlog-group-consumer
# 流程消息消费对立
spring.cloud.stream.bindings.msgInput.destination= jpaas-message
spring.cloud.stream.bindings.msgInput.group= message-group-consumer
文档更新时间: 2022-06-22 09:45   作者:zyg