<dependency>
<groupId>com.avides.spring</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.7.0</version>
</dependency>
- Rabbit-Configuration
- Known issues
- Dependencies
- Metrics
- MessagePostProcessors
- Example
- DefaultProperties
- QueueProperties
- RabbitTemplateProperties
- RabbitAdminProperties
- MessageConverterProperties
- ExchangeProperties
- ListenerProperties
- CustomConnectionFactoryProperties
- BeanReferenceConnectionFactoryProperties
docker run \
-d \
--name rabbitmq \
--hostname rabbitmq \
--restart=always \
--memory=500MB \
-v PATH:/var/lib/rabbitmq \
-e RABBITMQ_NODENAME=rabbit@localhost \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:VERSION
The RABBITMQ_NODENAME
environment variable is necessary!
The rabbit user needs at least MONITORING
as tag!
The rabbit template needs to be autowired with @Lazy
!
If one property needs to be overridden in other profiles the complete prefix/collection needs to be copied!
This project needs micrometer-core
as dependency with a bean of meterRegistry
.
counter_rabbit_listener_event_count
counter_rabbit_listener_event_total_duration_milliseconds_count
rabbit_outbound_message_total
- Counter for each outbound grouped by the bean name of the rabbit template
MessagePostProcessor that adds the configured app-id as the appId-Header.
Prefers the value of spring.rabbitmq.outbound.global.before-publish-post-processor.appid-enricher.app-id
as app-id. If no property value exists, info.artifactId
or else UNKNOWN
is used.
Could be disabled by setting spring.rabbitmq.outbound.global.before-publish-post-processor.appid-enricher.enabled
to false.
MessagePostProcessor that adds metrics for each outbound message.
Enabled if spring.rabbitmq.outbound.global.before-publish-post-processor.counting-outbound.enabled
is true or not specified.
Using MeterRegistry will increment a counter with the bean name of the template as a tag for each message.
Example for one connection factory
spring.rabbitmq.addresses=localhost
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.exchange.name=com.example.exchange
spring.rabbitmq.queues[0].name=com.example.queue.zero
spring.rabbitmq.queues[0].routing-keys[0]=routingkey.zero.zero
spring.rabbitmq.queues[0].routing-keys[1]=routingkey.zero.one
spring.rabbitmq.queues[0].routing-keys[2]=routingkey.zero.two.*
spring.rabbitmq.queues[0].limit=500000
spring.rabbitmq.queues[0].listener.bean-name=myListenerZero
spring.rabbitmq.queues[1].name=com.example.queue.one
spring.rabbitmq.queues[1].routing-key=routingkey.one
spring.rabbitmq.queues[1].limit=100000
spring.rabbitmq.queues[1].listener.bean-name=myListenerOne
spring.rabbitmq.outbounds[0].bean-name=myRabbitTemplateZero
spring.rabbitmq.outbounds[0].routing-key=another.routingkey.zero
spring.rabbitmq.outbounds[1].bean-name=myRabbitTemplateOne
spring.rabbitmq.outbounds[1].routing-key=another.routingkey.one.{placeholder}
spring.rabbitmq.outbounds[2].bean-name=myRabbitTemplateTwo
spring.rabbitmq.outbounds[2].routing-key=another.routingkey.two
spring.rabbitmq.outbounds[2].exchange.name=com.example.another.exchange
Example for multiple connection factories
spring.rabbitmq.connections[0].addresses=localhost
spring.rabbitmq.connections[0].username=guest
spring.rabbitmq.connections[0].password=guest
spring.rabbitmq.connections[0].virtual-host=/
spring.rabbitmq.connections[0].bean-name=myConnectionFactoryZero
spring.rabbitmq.connections[1].addresses=localhost
spring.rabbitmq.connections[1].username=guest
spring.rabbitmq.connections[1].password=guest
spring.rabbitmq.connections[1].virtual-host=/
spring.rabbitmq.connections[1].bean-name=myConnectionFactoryOne
spring.rabbitmq.message-converter.bean-name=myMessageConverter
spring.rabbitmq.exchange.name=com.example.exchange
#myConnectionFactoryZero
spring.rabbitmq.queues[0].name=com.example.queue.zero
spring.rabbitmq.queues[0].routing-key=routingkey.zero
spring.rabbitmq.queues[0].exchange.name=com.example.exchange.zero
spring.rabbitmq.queues[0].exchange.type=DIRECT
spring.rabbitmq.queues[0].limit=500000
spring.rabbitmq.queues[0].listener.bean-name=myListenerZero
spring.rabbitmq.queues[0].listener.prefetch-count=55
spring.rabbitmq.queues[0].listener.max-concurrent-consumers=2
spring.rabbitmq.queues[0].rabbit-admin.bean-name=myRabbitAdminZero
spring.rabbitmq.queues[0].rabbit-admin.connection-factory.bean-name=myConnectionFactoryZero
spring.rabbitmq.outbounds[0].bean-name=myRabbitTemplateZero
spring.rabbitmq.outbounds[0].routing-key=another.routingkey.zero
spring.rabbitmq.outbounds[0].connection-factory.bean-name=myConnectionFactoryZero
spring.rabbitmq.outbounds[0].exchange.name=com.example.exchange.zero
spring.rabbitmq.outbounds[0].exchange.type=DIRECT
#myConnectionFactoryOne
spring.rabbitmq.queues[1].name=com.example.queue.one
spring.rabbitmq.queues[1].routing-key=routingkey.one
spring.rabbitmq.queues[1].limit=10000
spring.rabbitmq.queues[1].listener.bean-name=myListenerOne
spring.rabbitmq.queues[1].listener.message-converter.bean-name=myConverterOne
spring.rabbitmq.queues[1].rabbit-admin.bean-name=myRabbitAdminOne
spring.rabbitmq.queues[1].rabbit-admin.connection-factory.bean-name=myConnectionFactoryOne
spring.rabbitmq.queues[2].name=com.example.queue.two
spring.rabbitmq.queues[2].routing-keys[0]=routingkey.two.zero
spring.rabbitmq.queues[2].routing-keys[1]=routingkey.two.one
spring.rabbitmq.queues[2].limit=500000
spring.rabbitmq.queues[2].listener.bean-name=myListenerTwo
spring.rabbitmq.queues[2].rabbit-admin.bean-name=myRabbitAdminOne
spring.rabbitmq.queues[2].rabbit-admin.connection-factory.bean-name=myConnectionFactoryOne
spring.rabbitmq.outbounds[1].bean-name=myRabbitTemplateOne
spring.rabbitmq.outbounds[1].routing-key=another.routingkey.one
spring.rabbitmq.outbounds[1].connection-factory.bean-name=myConnectionFactoryOne
Example for an implementation of a SpringRabbitListener
@Component
public class MyListener extends AbstractSpringRabbitListener<MyData>
{
@Autowired
private MyService myService;
@Override
protected void handleEvent(MyData myData)
{
myDataService.doSomething(myData);
}
}
This properties are used to set default values. If there are specific properties (e.g spring.rabbitmq.queues[0].exchange.(ExchangeProperties)
) the specefic properties are used.
See MessageConverterProperties
@Min(1)
Default 500. Could be overridden by each listener.
spring.rabbitmq.prefetch-count=50
@Min(1)
Default 1
spring.rabbitmq.max-concurrent-consumers=2
@Range(min = 1, max = 65535)
Default 15672
spring.rabbitmq.api-port=65535
Configures if the queue and its listener should be created. The possible existing queue will not be deleted!
Default: true
spring.rabbitmq.queues[0].creation-enabled=false
@NotBlank
Configures the name of the queue. The name is also used to create the DLX (name + ".dlx").
spring.rabbitmq.queues[0].name=com.example.queue
Configures the binding of the queue to the exchange.
Either routing-key
or routing-keys[*]
is necessary.
spring.rabbitmq.queues[0].routing-key=example.routingkey
Configures the bindings of the queue to the exchange.
Either routing-key
or routing-keys[*]
is necessary.
spring.rabbitmq.queues[0].routing-keys[0]=example.routingkey.one
spring.rabbitmq.queues[0].routing-keys[1]=example.routingkey.two
spring.rabbitmq.queues[0].routing-keys[2]=example.routingkey.three.*
@Min(1)
Configures the limit of the queue and his DLX and is necessary (min value of 1).
spring.rabbitmq.queues[0].limit=10000
Configures the Queue.durable property. Default is true. Is used for the queue AND his DLX.
spring.rabbitmq.queues[0].durable=false
Configures the Queue.exclusive. Default is false. Is used for the queue AND his DLX.
spring.rabbitmq.queues[0].exclusive=false
Adds additional arguments for the queue.
x-dead-letter-exchange
, x-dead-letter-routing-key
and x-max-length
are added and would override existing entries with the same key.
Is ONLY used for the queue NOT his DLX!
spring.rabbitmq.queues[0].arguments[someAdditionalQueueArgumentsKey]=Value
@Valid
@NotNull
@Valid
@NotBlank
Configures the autowired bean name of the rabbit template.
One limit: Needs to be autowired with @Lazy
!
spring.rabbitmq.outbounds[0].bean-name=myRabbitTemplte
@NotBlank
Configures the routing key for the rabbit template.
spring.rabbitmq.outbounds[0].routing-key=example.routingkey
@Valid
@Valid
See MessageConverterProperties
@Valid
See BeanReferenceConnectionFactoryProperties
@NotBlank
Default: "rabbitAdmin"
spring.rabbitmq.queues[0].rabbit-admin.bean-name=myRabbitAdmin
See BeanReferenceConnectionFactoryProperties
This properties are resolved like this:
- custom properties
- default properties
- check if the context already contains one message converter
@NotBlank
The autowired name of the bean.
spring.rabbitmq.outbounds[0].message-converter.bean-name=jaxbMessageConverter
@NotBlank
The name of the exchange.
spring.rabbitmq.exchange.name=com.example
@NotNull
Default: TOPIC Values: TOPIC, DIRECT
spring.rabbitmq.exchange.type=TOPIC
Configures if the listener should be created.
Default: true
spring.rabbitmq.queues[0].listener.creation-enabled=false
@NotBlank
The name of the SpringRabbitListener.
spring.rabbitmq.queues[0].listener.bean-name=myListener
@Valid
See MessageConverterProperties
Could be null or @Min(1)
spring.rabbitmq.queues[0].listener.prefetch-count=30
Could be null or @Min(1)
Default: 1
spring.rabbitmq.queues[0].listener.max-concurrent-consumers=2
These properties should be used if more than one connection factory is needed. When used, make sure that the RabbitAutoConfiguration is disabled / excluded.
@NotBlank
spring.rabbitmq.connections[0].addresses=localhost
@NotBlank
spring.rabbitmq.connections[0].username=guest
@NotBlank
spring.rabbitmq.connections[0].password=guest
@NotBlank Default: /
spring.rabbitmq.connections[0].virtual-host=integrationtest
@NotBlank
spring.rabbitmq.connections[0].bean-name=myConnectionFactory
@Range(min = 1, max = 65535) Default: 15672
spring.rabbitmq.connections[0].api-port=15673
@NotBlank
Reference name of the specific custom connection factory CustomConnectionFactoryProperties.bean-name.
spring.rabbitmq.outbounds[1].connection-factory.bean-name=myConnectionFactory