Spring Boot application integrates multiple RabbitMQ quickly.
- Import dependencies
<dependency>
<groupId>cn.unikue.springstarter</groupId>
<artifactId>multiple-rabbit-spring-boot-starter</artifactId>
<version>LATEST</version>
</dependency>By default, this starter will auto take effect, you can turn it off by
spring.multiple-rabbit.enabled = false
- Configure Spring Boot
application.ymlwith prefixspring.multiple-rabbit
spring:
multiple-rabbit:
primary:
host: '192.168.0.1'
delayed-exchange:
name: 'delayed-exchange'
type: direct
durable: true
auto-delete: true
secondary:
host: '192.168.0.2'
tertiary:
host: '192.168.0.3'This starter supports 3 RabbitMQ
ConnectionFactoryat most. (Three strikes and you're out)
- Optional feature: If you want to use rabbitmq delayed message exchange, you should download the
rabbitmq_delayed_message_exchangeplugin and install it first like this:
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
The plugin download page: https://github.com/rabbitmq/rabbitmq-delayed-message-exchange
- Configure your beans with the following beans by
@Autowired/@Resourceannotation, combined with@Qualifierannotation (takeprimaryas an example)
| Bean Type | Qualifier |
|---|---|
| CachingConnectionFactory | PrimaryRabbitAutoConfiguration.CONNECTION_FACTORY |
| RabbitTemplate | PrimaryRabbitAutoConfiguration.RABBIT_TEMPLATE |
| RabbitMessagingTemplate | PrimaryRabbitAutoConfiguration.RABBIT_MESSAGING_TEMPLATE |
| AmqpAdmin | PrimaryRabbitAutoConfiguration.AMQP_ADMIN |
| CustomExchange | PrimaryRabbitAutoConfiguration.DELAYED_EXCHANGE |
- Github: https://github.com/unikueltd/multiple-rabbit-spring-boot-starter
- RabbitMQ github: https://github.com/rabbitmq/rabbitmq-java-client
- RabbitMQ homepage: https://rabbitmq.com
- jdk 17+
This project is under the Apache License 2.0
See the NOTICE.txt file for required notices and attributions.
You like this package? Then donate to us to support the development.
Beijing Unikue Network Technology Ltd.
- Unikue: https://unikue.cn