说明

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

在平台中切换消息队列

切换RABBITMQ

修改 jpaas-share 下的 pom.xml

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
  4. </dependency>

修改 nacos 配置

修改 nacos-config-dev.properties 或 nacos-config-prod.properties

  1. spring.cloud.stream.binders.local_rabbit.type= rabbit
  2. spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.host=192.168.1.10
  3. spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.port=5672
  4. spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.username=admin
  5. spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.password=admin
  6. spring.cloud.stream.binders.local_rabbit.environment.spring.rabbitmq.virtual-host= /

修改 application.properties 文件

  1. # 系统消息
  2. spring.cloud.stream.bindings.output.destination=bpmmessage
  3. spring.cloud.stream.bindings.output.group= bpmmessage-group
  4. spring.cloud.stream.bindings.output.binder = local_rabbit
  5. spring.cloud.stream.bindings.input.destination= bpmmessage
  6. spring.cloud.stream.bindings.input.group= bpmmessage-group-consumer
  7. spring.cloud.stream.bindings.input.binder = local_rabbit
  8. # 邮件消息
  9. spring.cloud.stream.bindings.mailOutput.destination=mail
  10. spring.cloud.stream.bindings.mailOutput.group= mail-group
  11. spring.cloud.stream.bindings.mailOutput.binder = local_rabbit
  12. spring.cloud.stream.bindings.mailInput.destination= mail
  13. spring.cloud.stream.bindings.mailInput.group= mail-group-consumer
  14. spring.cloud.stream.bindings.mailInput.binder = local_rabbit
  15. # 流程异步事件
  16. spring.cloud.stream.bindings.eventOutput.destination=event
  17. spring.cloud.stream.bindings.eventOutput.group= event-group
  18. spring.cloud.stream.bindings.eventOutput.binder = local_rabbit
  19. spring.cloud.stream.bindings.eventInput.destination= event
  20. spring.cloud.stream.bindings.eventInput.group= event-group-consumer
  21. spring.cloud.stream.bindings.eventInput.binder = local_rabbit
  22. # 附件转换消息
  23. spring.cloud.stream.bindings.fileOutput.destination=file
  24. spring.cloud.stream.bindings.fileOutput.group= file-group
  25. spring.cloud.stream.bindings.fileOutput.binder = local_rabbit
  26. spring.cloud.stream.bindings.fileInput.destination= file
  27. spring.cloud.stream.bindings.fileInput.group= file-group-consumer
  28. spring.cloud.stream.bindings.fileInput.binder = local_rabbit

切换到ROCKETMQ

修改 jpaas-share 下的 pom.xml

  1. <dependency>
  2. <groupId>com.alibaba.cloud</groupId>
  3. <artifactId>spring-cloud-stream-binder-rocketmq</artifactId>
  4. </dependency>

修改NACOS 配置

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

修改 application.properties 文件

  1. # ROCKETMQ系统消息
  2. spring.cloud.stream.bindings.output.destination=bpmmessage
  3. spring.cloud.stream.bindings.output.group= bpmmessage-group
  4. spring.cloud.stream.bindings.input.destination= bpmmessage
  5. spring.cloud.stream.bindings.input.group= bpmmessage-group-consumer
  6. # 邮件消息
  7. spring.cloud.stream.bindings.mailOutput.destination=mail
  8. spring.cloud.stream.bindings.mailOutput.group= mail-group
  9. spring.cloud.stream.bindings.mailInput.destination= mail
  10. spring.cloud.stream.bindings.mailInput.group= mail-group-consumer
  11. # 流程异步事件
  12. spring.cloud.stream.bindings.eventOutput.destination=event
  13. spring.cloud.stream.bindings.eventOutput.group= event-group
  14. spring.cloud.stream.bindings.eventInput.destination= event
  15. spring.cloud.stream.bindings.eventInput.group= event-group-consumer
  16. # 附件转换消息
  17. spring.cloud.stream.bindings.fileOutput.destination=file
  18. spring.cloud.stream.bindings.fileOutput.group= file-group
  19. spring.cloud.stream.bindings.fileInput.destination= file
  20. spring.cloud.stream.bindings.fileInput.group= file-group-consumer
文档更新时间: 2021-07-19 18:39   作者:zyg