GitHub - spring-attic/spring-cloud-stream-binder-rabbit · GitHub
Skip to content You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert This repository was archived by the owner on Nov 20, 2024. It is now read-only. Branches Tags Open more actions menu Latest commit History 414 Commits 414 Commits Folders and files Name Name Last commit message Last commit date .github/ ISSUE_TEMPLATE .github/ ISSUE_TEMPLATE .mvn .mvn ci-docker-compose ci-docker-compose docs docs spring-cloud-starter-stream-rabbit spring-cloud-starter-stream-rabbit spring-cloud-stream-binder-rabbit-core spring-cloud-stream-binder-rabbit-core spring-cloud-stream-binder-rabbit-test-support spring-cloud-stream-binder-rabbit-test-support spring-cloud-stream-binder-rabbit spring-cloud-stream-binder-rabbit src/ checkstyle src/ checkstyle .gitignore .gitignore .settings.xml .settings.xml LICENSE LICENSE README.adoc README.adoc README.md README.md mvnw mvnw mvnw.cmd mvnw.cmd pom.xml pom.xml update-version.sh update-version.sh Repository files navigation ANNOUNCEMENT IMPORTANT: This repository is now migrated as part of core Spring Cloud Stream - https://github.com/spring-cloud/spring-cloud-stream .
Please create new issues over at the core repository. Usage To use the RabbitMQ binder, you can add it to your Spring Cloud Stream application, by using the following Maven coordinates: < dependency > < groupId >org.springframework.cloud</ groupId > < artifactId >spring-cloud-stream-binder-rabbit</ artifactId > </ dependency > Alternatively, you can use the Spring Cloud Stream RabbitMQ Starter, as follows: < dependency > < groupId >org.springframework.cloud</ groupId > < artifactId >spring-cloud-starter-stream-rabbit</ artifactId > </ dependency > RabbitMQ Binder Overview The following simplified diagram shows how the RabbitMQ binder operates: Figure 1.
RabbitMQ Binder By default, the RabbitMQ Binder implementation maps each destination to a TopicExchange . For each consumer group, a Queue is bound to that TopicExchange . Each consumer instance has a corresponding RabbitMQ Consumer instance for its group’s Queue . For partitioned producers and consumers, the queues are suffixed with the partition index and use the partition index as the routing key. For anonymous consumers (those with no group property), an auto-delete queue (with a randomized unique name) is used.
By using the optional autoBindDlq option, you can configure the binder to create and configure dead-letter queues (DLQs) (and a dead-letter exchange DLX , as well as routing infrastructure). By default, the dead letter queue has the name of the destination, appended with .dlq . If retry is enabled ( maxAttempts > 1 ), failed messages are delivered to the DLQ after retries are exhausted. If retry is disabled ( maxAttempts = 1 ), you should set requeueRejected to false (the default) so that failed messages are routed to the DLQ, instead of being re-queued.
In addition, republishToDlq causes the binder to publish a failed message to the DLQ (instead of rejecting it). This feature lets additional information (such as the stack trace in the x-exception-stacktrace header) be added to the message in headers. See the frameMaxHeadroom property for information about truncated stack traces. This option does not need retry enabled. You can republish a failed message after just one attempt.
Starting with version 1.2, you can configure the delivery mode of republished messages. See the republishDeliveryMode property . If the stream listener throws an ImmediateAcknowledgeAmqpException , the DLQ is bypassed and the message simply discarded. Starting with version 2.1, this is true regardless of the setting of republishToDlq ; previously it was only the case when republishToDlq was false . Important Setting requeueRejected to true (with republishToDlq=false ) causes the message to be re-queued and redelivered continually, which is likely not what you want unless the reason for the failure is transient.
In general, you should enable retry within the binder by setting maxAttempts to greater than one or by setting republishToDlq to true . Starting with version 3.1.2, if the consumer is marked as transacted , publishing to the DLQ will participate in the transaction. This allows the transaction to roll back if the publishing fails for some reason (for example, if the user is not authorized to publish to the dead letter exchange).
In addition, if the connection factory is configured for publisher confirms or returns, the publication to the DLQ will wait for the confirmation and check for a returned message. If a negative acknowledgment or returned message is received, the binder will throw an AmqpRejectAndDontRequeueException , allowing the broker to take care of publishing to the DLQ as if the republishToDlq property is false . See RabbitMQ Binder Properties for more information about these properties.
The framework does not provide any standard mechanism to consume dead-letter messages (or to re-route them back to the primary queue). Some options are described in [rabbit-dlq-processing] . Note When multiple RabbitMQ binders are used in a Spring Cloud Stream application, it is important to disable 'RabbitAutoConfiguration' to avoid the same configuration from RabbitAutoConfiguration being applied to the two binders.
You can exclude the class by using the @SpringBootApplication annotation. Starting with version 2.0, the RabbitMessageChannelBinder sets the RabbitTemplate.userPublisherConnection property to true so that the non-transactional producers avoid deadlocks on consumers, which can happen if cached connections are blocked because of a memory alarm on the broker. Note Currently, a multiplex consumer (a single consumer listening to multiple queues) is only supported for message-driven consumers; polled consumers can only retrieve messages from a single queue.
Configuration Options This section contains settings specific to the RabbitMQ Binder and bound channels. For general binding configuration options and properties, see the Spring Cloud Stream core documentation . RabbitMQ Binder Properties By default, the RabbitMQ binder uses Spring Boot’s ConnectionFactory . Conseuqently, it supports all Spring Boot configuration options for RabbitMQ. (For reference, see the Spring Boot documentation ).
RabbitMQ configuration options use the spring.rabbitmq prefix. In addition to Spring Boot options, the RabbitMQ binder supports the following properties: spring.cloud.stream.rabbit.binder.adminAddresses A comma-separated list of RabbitMQ management plugin URLs. Only used when nodes contains more than one entry. Each entry in this list must have a corresponding entry in spring.rabbitmq.addresses . Only needed if you use a RabbitMQ cluster and wish to consume from the node that hosts the queue.
See Queue Affinity and the LocalizedQueueConnectionFactory for more information. Default: empty. spring.cloud.stream.rabbit.binder.nodes A comma-separated list of RabbitMQ node names. When more than one entry, used to locate the server address where a queue is located. Each entry in this list must have a corresponding entry in spring.rabbitmq.addresses . Only needed if you use a RabbitMQ cluster and wish to consume from the node that hosts the queue.
See Queue Affinity and the LocalizedQueueConnectionFactory for more information. Default: empty. spring.cloud.stream.rabbit.binder.compressionLevel The compression level for compressed bindings. See java.util.zip.Deflater . Default: 1 (BEST_LEVEL). spring.cloud.stream.binder.connection-name-prefix A connection name prefix used to name the connection(s) created by this binder. The name is this prefix followed by #n , where n increments each time a new connection is opened.
Default: none (Spring AMQP default). RabbitMQ Consumer Properties The following properties are available for Rabbit consumers only and mus
The rest of this page is on the live site.