1497 lines
68 KiB
XML
1497 lines
68 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<?asciidoc-toc maxdepth="4"?>
|
|
<?asciidoc-numbered?>
|
|
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
|
|
<info>
|
|
<title>Spring Cloud Stream RabbitMQ Binder Reference Guide</title>
|
|
<date>2019-06-06</date>
|
|
<author>
|
|
<personname>
|
|
<firstname>Sabby Anandan, Marius Bogoevici, Eric Bottard, Mark Fisher, Ilayaperumal Gopinathan, Gunnar Hillert, Mark Pollack, Patrick Peralta, Glenn Renfro, Thomas Risberg, Dave Syer, David Turanski, Janne Valkealahti, Benjamin Klein, Gary Russell, Jay Bryant</firstname>
|
|
</personname>
|
|
</author>
|
|
<authorinitials>S</authorinitials>
|
|
</info>
|
|
<part xml:id="_reference_guide">
|
|
<title>Reference Guide</title>
|
|
<partintro>
|
|
<simpara>This guide describes the RabbitMQ implementation of the Spring Cloud Stream Binder.
|
|
It contains information about its design, usage and configuration options, as well as information on how the Stream Cloud Stream concepts map into RabbitMQ specific constructs.</simpara>
|
|
</partintro>
|
|
<chapter xml:id="_usage">
|
|
<title>Usage</title>
|
|
<simpara>To use the RabbitMQ binder, you can add it to your Spring Cloud Stream application, by using the following Maven coordinates:</simpara>
|
|
<programlisting language="xml" linenumbering="unnumbered"><dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
|
|
</dependency></programlisting>
|
|
<simpara>Alternatively, you can use the Spring Cloud Stream RabbitMQ Starter, as follows:</simpara>
|
|
<programlisting language="xml" linenumbering="unnumbered"><dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
|
</dependency></programlisting>
|
|
</chapter>
|
|
<chapter xml:id="_rabbitmq_binder_overview">
|
|
<title>RabbitMQ Binder Overview</title>
|
|
<simpara>The following simplified diagram shows how the RabbitMQ binder operates:</simpara>
|
|
<figure>
|
|
<title>RabbitMQ Binder</title>
|
|
<mediaobject>
|
|
<imageobject>
|
|
<imagedata fileref="https://raw.github.com/spring-cloud/spring-cloud-stream-binder-rabbit/master/docs/src/main/asciidoc/images/rabbit-binder.png" width="50%"/>
|
|
</imageobject>
|
|
<textobject><phrase>rabbit binder</phrase></textobject>
|
|
</mediaobject>
|
|
</figure>
|
|
<simpara>By default, the RabbitMQ Binder implementation maps each destination to a <literal>TopicExchange</literal>.
|
|
For each consumer group, a <literal>Queue</literal> is bound to that <literal>TopicExchange</literal>.
|
|
Each consumer instance has a corresponding RabbitMQ <literal>Consumer</literal> instance for its group’s <literal>Queue</literal>.
|
|
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 <literal>group</literal> property), an auto-delete queue (with a randomized unique name) is used.</simpara>
|
|
<simpara>By using the optional <literal>autoBindDlq</literal> option, you can configure the binder to create and configure dead-letter queues (DLQs) (and a dead-letter exchange <literal>DLX</literal>, as well as routing infrastructure).
|
|
By default, the dead letter queue has the name of the destination, appended with <literal>.dlq</literal>.
|
|
If retry is enabled (<literal>maxAttempts > 1</literal>), failed messages are delivered to the DLQ after retries are exhausted.
|
|
If retry is disabled (<literal>maxAttempts = 1</literal>), you should set <literal>requeueRejected</literal> to <literal>false</literal> (the default) so that failed messages are routed to the DLQ, instead of being re-queued.
|
|
In addition, <literal>republishToDlq</literal> 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 <literal>x-exception-stacktrace</literal> header) be added to the message in headers.
|
|
See the <link linkend="spring-cloud-stream-rabbit-frame-max-headroom"><literal>frameMaxHeadroom</literal> property</link> 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 <link linkend="spring-cloud-stream-rabbit-republish-delivery-mode"><literal>republishDeliveryMode</literal> property</link>.</simpara>
|
|
<simpara>If the stream listener throws an <literal>ImmediateAcknowledgeAmqpException</literal>, the DLQ is bypassed and the message simply discarded.
|
|
Starting with version 2.1, this is true regardless of the setting of <literal>republishToDlq</literal>; previously it was only the case when <literal>republishToDlq</literal> was <literal>false</literal>.</simpara>
|
|
<important>
|
|
<simpara>Setting <literal>requeueRejected</literal> to <literal>true</literal> (with <literal>republishToDlq=false</literal> ) 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 <literal>maxAttempts</literal> to greater than one or by setting <literal>republishToDlq</literal> to <literal>true</literal>.</simpara>
|
|
</important>
|
|
<simpara>See <xref linkend="rabbit-binder-properties"/> for more information about these properties.</simpara>
|
|
<simpara>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 <xref linkend="rabbit-dlq-processing"/>.</simpara>
|
|
<note>
|
|
<simpara>When multiple RabbitMQ binders are used in a Spring Cloud Stream application, it is important to disable 'RabbitAutoConfiguration' to avoid the same configuration from <literal>RabbitAutoConfiguration</literal> being applied to the two binders.
|
|
You can exclude the class by using the <literal>@SpringBootApplication</literal> annotation.</simpara>
|
|
</note>
|
|
<simpara>Starting with version 2.0, the <literal>RabbitMessageChannelBinder</literal> sets the <literal>RabbitTemplate.userPublisherConnection</literal> property to <literal>true</literal> so that the non-transactional producers avoid deadlocks on consumers, which can happen if cached connections are blocked because of a <link xl:href="https://www.rabbitmq.com/memory.html">memory alarm</link> on the broker.</simpara>
|
|
<note>
|
|
<simpara>Currently, a <literal>multiplex</literal> consumer (a single consumer listening to multiple queues) is only supported for message-driven conssumers; polled consumers can only retrieve messages from a single queue.</simpara>
|
|
</note>
|
|
</chapter>
|
|
<chapter xml:id="_configuration_options">
|
|
<title>Configuration Options</title>
|
|
<simpara>This section contains settings specific to the RabbitMQ Binder and bound channels.</simpara>
|
|
<simpara>For general binding configuration options and properties, see the <link xl:href="https://github.com/spring-cloud/spring-cloud-stream/blob/master/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc#configuration-options">Spring Cloud Stream core documentation</link>.</simpara>
|
|
<section xml:id="rabbit-binder-properties">
|
|
<title>RabbitMQ Binder Properties</title>
|
|
<simpara>By default, the RabbitMQ binder uses Spring Boot’s <literal>ConnectionFactory</literal>.
|
|
Conseuqently, it supports all Spring Boot configuration options for RabbitMQ.
|
|
(For reference, see the <link xl:href="https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties">Spring Boot documentation</link>).
|
|
RabbitMQ configuration options use the <literal>spring.rabbitmq</literal> prefix.</simpara>
|
|
<simpara>In addition to Spring Boot options, the RabbitMQ binder supports the following properties:</simpara>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>spring.cloud.stream.rabbit.binder.adminAddresses</term>
|
|
<listitem>
|
|
<simpara>A comma-separated list of RabbitMQ management plugin URLs.
|
|
Only used when <literal>nodes</literal> contains more than one entry.
|
|
Each entry in this list must have a corresponding entry in <literal>spring.rabbitmq.addresses</literal>.
|
|
Only needed if you use a RabbitMQ cluster and wish to consume from the node that hosts the queue.
|
|
See <link xl:href="https://docs.spring.io/spring-amqp/reference/html/_reference.html#queue-affinity">Queue Affinity and the LocalizedQueueConnectionFactory</link> for more information.</simpara>
|
|
<simpara>Default: empty.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>spring.cloud.stream.rabbit.binder.nodes</term>
|
|
<listitem>
|
|
<simpara>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 <literal>spring.rabbitmq.addresses</literal>.
|
|
Only needed if you use a RabbitMQ cluster and wish to consume from the node that hosts the queue.
|
|
See <link xl:href="https://docs.spring.io/spring-amqp/reference/html/_reference.html#queue-affinity">Queue Affinity and the LocalizedQueueConnectionFactory</link> for more information.</simpara>
|
|
<simpara>Default: empty.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>spring.cloud.stream.rabbit.binder.compressionLevel</term>
|
|
<listitem>
|
|
<simpara>The compression level for compressed bindings.
|
|
See <literal>java.util.zip.Deflater</literal>.</simpara>
|
|
<simpara>Default: <literal>1</literal> (BEST_LEVEL).</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>spring.cloud.stream.binder.connection-name-prefix</term>
|
|
<listitem>
|
|
<simpara>A connection name prefix used to name the connection(s) created by this binder.
|
|
The name is this prefix followed by <literal>#n</literal>, where <literal>n</literal> increments each time a new connection is opened.</simpara>
|
|
<simpara>Default: none (Spring AMQP default).</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</section>
|
|
<section xml:id="_rabbitmq_consumer_properties">
|
|
<title>RabbitMQ Consumer Properties</title>
|
|
<simpara>The following properties are available for Rabbit consumers only and must be prefixed with <literal>spring.cloud.stream.rabbit.bindings.<channelName>.consumer.</literal>.</simpara>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>acknowledgeMode</term>
|
|
<listitem>
|
|
<simpara>The acknowledge mode.</simpara>
|
|
<simpara>Default: <literal>AUTO</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>anonymousGroupPrefix</term>
|
|
<listitem>
|
|
<simpara>When the binding has no <literal>group</literal> property, an anonymous, auto-delete queue is bound to the destination exchange.
|
|
The default naming stragegy for such queues results in a queue named <literal>anonymous.<base64 representation of a UUID></literal>.
|
|
Set this property to change the prefix to something other than the default.</simpara>
|
|
<simpara>Default: <literal>anonymous.</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>autoBindDlq</term>
|
|
<listitem>
|
|
<simpara>Whether to automatically declare the DLQ and bind it to the binder DLX.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>bindingRoutingKey</term>
|
|
<listitem>
|
|
<simpara>The routing key with which to bind the queue to the exchange (if <literal>bindQueue</literal> is <literal>true</literal>).
|
|
For partitioned destinations, <literal>-<instanceIndex></literal> is appended.</simpara>
|
|
<simpara>Default: <literal>#</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>bindQueue</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the queue and bind it to the destination exchange.
|
|
Set it to <literal>false</literal> if you have set up your own infrastructure and have previously created and bound the queue.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>consumerTagPrefix</term>
|
|
<listitem>
|
|
<simpara>Used to create the consumer tag(s); will be appended by <literal>#n</literal> where <literal>n</literal> increments for each consumer created.
|
|
Example: <literal>${spring.application.name}-${spring.cloud.stream.bindings.input.group}-${spring.cloud.stream.instance-index}</literal>.</simpara>
|
|
<simpara>Default: none - the broker will generate random consumer tags.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>containerType</term>
|
|
<listitem>
|
|
<simpara>Select the type of listener container to be used.
|
|
See <link xl:href="https://docs.spring.io/spring-amqp/reference/html/_reference.html#choose-container">Choosing a Container</link> in the Spring AMQP documentation for more information.</simpara>
|
|
<simpara>Default: <literal>simple</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterQueueName</term>
|
|
<listitem>
|
|
<simpara>The name of the DLQ</simpara>
|
|
<simpara>Default: <literal>prefix+destination.dlq</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterExchange</term>
|
|
<listitem>
|
|
<simpara>A DLX to assign to the queue.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.</simpara>
|
|
<simpara>Default: 'prefix+DLX'</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterExchangeType</term>
|
|
<listitem>
|
|
<simpara>The type of the DLX to assign to the queue.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.</simpara>
|
|
<simpara>Default: 'direct'</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterRoutingKey</term>
|
|
<listitem>
|
|
<simpara>A dead letter routing key to assign to the queue.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.</simpara>
|
|
<simpara>Default: <literal>destination</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>declareDlx</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the dead letter exchange for the destination.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.
|
|
Set to <literal>false</literal> if you have a pre-configured DLX.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>declareExchange</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the exchange for the destination.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>delayedExchange</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the exchange as a <literal>Delayed Message Exchange</literal>.
|
|
Requires the delayed message exchange plugin on the broker.
|
|
The <literal>x-delayed-type</literal> argument is set to the <literal>exchangeType</literal>.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqDeadLetterExchange</term>
|
|
<listitem>
|
|
<simpara>If a DLQ is declared, a DLX to assign to that queue.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqDeadLetterRoutingKey</term>
|
|
<listitem>
|
|
<simpara>If a DLQ is declared, a dead letter routing key to assign to that queue.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqExpires</term>
|
|
<listitem>
|
|
<simpara>How long before an unused dead letter queue is deleted (in milliseconds).</simpara>
|
|
<simpara>Default: <literal>no expiration</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqLazy</term>
|
|
<listitem>
|
|
<simpara>Declare the dead letter queue with the <literal>x-queue-mode=lazy</literal> argument.
|
|
See <link xl:href="https://www.rabbitmq.com/lazy-queues.html"><quote>Lazy Queues</quote></link>.
|
|
Consider using a policy instead of this setting, because using a policy allows changing the setting without deleting the queue.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxLength</term>
|
|
<listitem>
|
|
<simpara>Maximum number of messages in the dead letter queue.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxLengthBytes</term>
|
|
<listitem>
|
|
<simpara>Maximum number of total bytes in the dead letter queue from all messages.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxPriority</term>
|
|
<listitem>
|
|
<simpara>Maximum priority of messages in the dead letter queue (0-255).</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqOverflowBehavior</term>
|
|
<listitem>
|
|
<simpara>Action to take when <literal>dlqMaxLength</literal> or <literal>dlqMaxLengthBytes</literal> is exceeded; currently <literal>drop-head</literal> or <literal>reject-publish</literal> but refer to the RabbitMQ documentation.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqTtl</term>
|
|
<listitem>
|
|
<simpara>Default time to live to apply to the dead letter queue when declared (in milliseconds).</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>durableSubscription</term>
|
|
<listitem>
|
|
<simpara>Whether the subscription should be durable.
|
|
Only effective if <literal>group</literal> is also set.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeAutoDelete</term>
|
|
<listitem>
|
|
<simpara>If <literal>declareExchange</literal> is true, whether the exchange should be auto-deleted (that is, removed after the last queue is removed).</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeDurable</term>
|
|
<listitem>
|
|
<simpara>If <literal>declareExchange</literal> is true, whether the exchange should be durable (that is, it survives broker restart).</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeType</term>
|
|
<listitem>
|
|
<simpara>The exchange type: <literal>direct</literal>, <literal>fanout</literal> or <literal>topic</literal> for non-partitioned destinations and <literal>direct</literal> or <literal>topic</literal> for partitioned destinations.</simpara>
|
|
<simpara>Default: <literal>topic</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exclusive</term>
|
|
<listitem>
|
|
<simpara>Whether to create an exclusive consumer.
|
|
Concurrency should be 1 when this is <literal>true</literal>.
|
|
Often used when strict ordering is required but enabling a hot standby instance to take over after a failure.
|
|
See <literal>recoveryInterval</literal>, which controls how often a standby instance attempts to consume.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>expires</term>
|
|
<listitem>
|
|
<simpara>How long before an unused queue is deleted (in milliseconds).</simpara>
|
|
<simpara>Default: <literal>no expiration</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>failedDeclarationRetryInterval</term>
|
|
<listitem>
|
|
<simpara>The interval (in milliseconds) between attempts to consume from a queue if it is missing.</simpara>
|
|
<simpara>Default: 5000</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<variablelist xml:id="spring-cloud-stream-rabbit-frame-max-headroom">
|
|
<varlistentry>
|
|
<term>frameMaxHeadroom</term>
|
|
<listitem>
|
|
<simpara>The number of bytes to reserve for other headers when adding the stack trace to a DLQ message header.
|
|
All headers must fit within the <literal>frame_max</literal> size configured on the broker.
|
|
Stack traces can be large; if the size plus this property exceeds <literal>frame_max</literal> then the stack trace will be truncated.
|
|
A WARN log will be written; consider increasing the <literal>frame_max</literal> or reducing the stack trace by catching the exception and throwing one with a smaller stack trace.</simpara>
|
|
<simpara>Default: 20000</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>headerPatterns</term>
|
|
<listitem>
|
|
<simpara>Patterns for headers to be mapped from inbound messages.</simpara>
|
|
<simpara>Default: <literal>['*']</literal> (all headers).</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>lazy</term>
|
|
<listitem>
|
|
<simpara>Declare the queue with the <literal>x-queue-mode=lazy</literal> argument.
|
|
See <link xl:href="https://www.rabbitmq.com/lazy-queues.html"><quote>Lazy Queues</quote></link>.
|
|
Consider using a policy instead of this setting, because using a policy allows changing the setting without deleting the queue.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxConcurrency</term>
|
|
<listitem>
|
|
<simpara>The maximum number of consumers.
|
|
Not supported when the <literal>containerType</literal> is <literal>direct</literal>.</simpara>
|
|
<simpara>Default: <literal>1</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxLength</term>
|
|
<listitem>
|
|
<simpara>The maximum number of messages in the queue.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxLengthBytes</term>
|
|
<listitem>
|
|
<simpara>The maximum number of total bytes in the queue from all messages.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxPriority</term>
|
|
<listitem>
|
|
<simpara>The maximum priority of messages in the queue (0-255).</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>missingQueuesFatal</term>
|
|
<listitem>
|
|
<simpara>When the queue cannot be found, whether to treat the condition as fatal and stop the listener container.
|
|
Defaults to <literal>false</literal> so that the container keeps trying to consume from the queue — for example, when using a cluster and the node hosting a non-HA queue is down.</simpara>
|
|
<simpara>Default: <literal>false</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>overflowBehavior</term>
|
|
<listitem>
|
|
<simpara>Action to take when <literal>maxLength</literal> or <literal>maxLengthBytes</literal> is exceeded; currently <literal>drop-head</literal> or <literal>reject-publish</literal> but refer to the RabbitMQ documentation.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>prefetch</term>
|
|
<listitem>
|
|
<simpara>Prefetch count.</simpara>
|
|
<simpara>Default: <literal>1</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>prefix</term>
|
|
<listitem>
|
|
<simpara>A prefix to be added to the name of the <literal>destination</literal> and queues.</simpara>
|
|
<simpara>Default: "".</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>queueDeclarationRetries</term>
|
|
<listitem>
|
|
<simpara>The number of times to retry consuming from a queue if it is missing.
|
|
Relevant only when <literal>missingQueuesFatal</literal> is <literal>true</literal>.
|
|
Otherwise, the container keeps retrying indefinitely.
|
|
Not supported when the <literal>containerType</literal> is <literal>direct</literal>.</simpara>
|
|
<simpara>Default: <literal>3</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>queueNameGroupOnly</term>
|
|
<listitem>
|
|
<simpara>When true, consume from a queue with a name equal to the <literal>group</literal>.
|
|
Otherwise the queue name is <literal>destination.group</literal>.
|
|
This is useful, for example, when using Spring Cloud Stream to consume from an existing RabbitMQ queue.</simpara>
|
|
<simpara>Default: false.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>recoveryInterval</term>
|
|
<listitem>
|
|
<simpara>The interval between connection recovery attempts, in milliseconds.</simpara>
|
|
<simpara>Default: <literal>5000</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>requeueRejected</term>
|
|
<listitem>
|
|
<simpara>Whether delivery failures should be re-queued when retry is disabled or <literal>republishToDlq</literal> is <literal>false</literal>.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<variablelist xml:id="spring-cloud-stream-rabbit-republish-delivery-mode">
|
|
<varlistentry>
|
|
<term>republishDeliveryMode</term>
|
|
<listitem>
|
|
<simpara>When <literal>republishToDlq</literal> is <literal>true</literal>, specifies the delivery mode of the republished message.</simpara>
|
|
<simpara>Default: <literal>DeliveryMode.PERSISTENT</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>republishToDlq</term>
|
|
<listitem>
|
|
<simpara>By default, messages that fail after retries are exhausted are rejected.
|
|
If a dead-letter queue (DLQ) is configured, RabbitMQ routes the failed message (unchanged) to the DLQ.
|
|
If set to <literal>true</literal>, the binder republishs failed messages to the DLQ with additional headers, including the exception message and stack trace from the cause of the final failure.
|
|
Also see the <link linkend="spring-cloud-stream-rabbit-frame-max-headroom">frameMaxHeadroom property</link>.</simpara>
|
|
<simpara>Default: false</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>transacted</term>
|
|
<listitem>
|
|
<simpara>Whether to use transacted channels.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>ttl</term>
|
|
<listitem>
|
|
<simpara>Default time to live to apply to the queue when declared (in milliseconds).</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>txSize</term>
|
|
<listitem>
|
|
<simpara>The number of deliveries between acks.
|
|
Not supported when the <literal>containerType</literal> is <literal>direct</literal>.</simpara>
|
|
<simpara>Default: <literal>1</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</section>
|
|
<section xml:id="_advanced_listener_container_configuration">
|
|
<title>Advanced Listener Container Configuration</title>
|
|
<simpara>To set listener container properties that are not exposed as binder or binding properties, add a single bean of type <literal>ListenerContainerCustomizer</literal> to the application context.
|
|
The binder and binding properties will be set and then the customizer will be called.
|
|
The customizer (<literal>configure()</literal> method) is provided with the queue name as well as the consumer group as arguments.</simpara>
|
|
</section>
|
|
<section xml:id="_rabbit_producer_properties">
|
|
<title>Rabbit Producer Properties</title>
|
|
<simpara>The following properties are available for Rabbit producers only and
|
|
must be prefixed with <literal>spring.cloud.stream.rabbit.bindings.<channelName>.producer.</literal>.</simpara>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>autoBindDlq</term>
|
|
<listitem>
|
|
<simpara>Whether to automatically declare the DLQ and bind it to the binder DLX.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>batchingEnabled</term>
|
|
<listitem>
|
|
<simpara>Whether to enable message batching by producers.
|
|
Messages are batched into one message according to the following properties (described in the next three entries in this list): 'batchSize', <literal>batchBufferLimit</literal>, and <literal>batchTimeout</literal>.
|
|
See <link xl:href="https://docs.spring.io/spring-amqp//reference/html/_reference.html#template-batching">Batching</link> for more information.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>batchSize</term>
|
|
<listitem>
|
|
<simpara>The number of messages to buffer when batching is enabled.</simpara>
|
|
<simpara>Default: <literal>100</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>batchBufferLimit</term>
|
|
<listitem>
|
|
<simpara>The maximum buffer size when batching is enabled.</simpara>
|
|
<simpara>Default: <literal>10000</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>batchTimeout</term>
|
|
<listitem>
|
|
<simpara>The batch timeout when batching is enabled.</simpara>
|
|
<simpara>Default: <literal>5000</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>bindingRoutingKey</term>
|
|
<listitem>
|
|
<simpara>The routing key with which to bind the queue to the exchange (if <literal>bindQueue</literal> is <literal>true</literal>).
|
|
Only applies to non-partitioned destinations.
|
|
Only applies if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>#</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>bindQueue</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the queue and bind it to the destination exchange.
|
|
Set it to <literal>false</literal> if you have set up your own infrastructure and have previously created and bound the queue.
|
|
Only applies if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>compress</term>
|
|
<listitem>
|
|
<simpara>Whether data should be compressed when sent.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>confirmAckChannel</term>
|
|
<listitem>
|
|
<simpara>When <literal>errorChannelEnabled</literal> is true, a channel to which to send positive delivery acknowledgments (aka publisher confirms).
|
|
If the channel does not exist, a <literal>DirectChannel</literal> is registered with this name.
|
|
The connection factory must be configured to enable publisher confirms.</simpara>
|
|
<simpara>Default: <literal>nullChannel</literal> (acks are discarded).</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterQueueName</term>
|
|
<listitem>
|
|
<simpara>The name of the DLQ
|
|
Only applies if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>prefix+destination.dlq</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterExchange</term>
|
|
<listitem>
|
|
<simpara>A DLX to assign to the queue.
|
|
Relevant only when <literal>autoBindDlq</literal> is <literal>true</literal>.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: 'prefix+DLX'</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterExchangeType</term>
|
|
<listitem>
|
|
<simpara>The type of the DLX to assign to the queue.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: 'direct'</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deadLetterRoutingKey</term>
|
|
<listitem>
|
|
<simpara>A dead letter routing key to assign to the queue.
|
|
Relevant only when <literal>autoBindDlq</literal> is <literal>true</literal>.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>destination</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>declareDlx</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the dead letter exchange for the destination.
|
|
Relevant only if <literal>autoBindDlq</literal> is <literal>true</literal>.
|
|
Set to <literal>false</literal> if you have a pre-configured DLX.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>declareExchange</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the exchange for the destination.</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>delayExpression</term>
|
|
<listitem>
|
|
<simpara>A SpEL expression to evaluate the delay to apply to the message (<literal>x-delay</literal> header).
|
|
It has no effect if the exchange is not a delayed message exchange.</simpara>
|
|
<simpara>Default: No <literal>x-delay</literal> header is set.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>delayedExchange</term>
|
|
<listitem>
|
|
<simpara>Whether to declare the exchange as a <literal>Delayed Message Exchange</literal>.
|
|
Requires the delayed message exchange plugin on the broker.
|
|
The <literal>x-delayed-type</literal> argument is set to the <literal>exchangeType</literal>.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>deliveryMode</term>
|
|
<listitem>
|
|
<simpara>The delivery mode.</simpara>
|
|
<simpara>Default: <literal>PERSISTENT</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqDeadLetterExchange</term>
|
|
<listitem>
|
|
<simpara>When a DLQ is declared, a DLX to assign to that queue.
|
|
Applies only if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqDeadLetterRoutingKey</term>
|
|
<listitem>
|
|
<simpara>When a DLQ is declared, a dead letter routing key to assign to that queue.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqExpires</term>
|
|
<listitem>
|
|
<simpara>How long (in milliseconds) before an unused dead letter queue is deleted.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no expiration</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqLazy</term>
|
|
<listitem>
|
|
<simpara>Declare the dead letter queue with the <literal>x-queue-mode=lazy</literal> argument.
|
|
See <link xl:href="https://www.rabbitmq.com/lazy-queues.html"><quote>Lazy Queues</quote></link>.
|
|
Consider using a policy instead of this setting, because using a policy allows changing the setting without deleting the queue.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxLength</term>
|
|
<listitem>
|
|
<simpara>Maximum number of messages in the dead letter queue.
|
|
Applies only if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxLengthBytes</term>
|
|
<listitem>
|
|
<simpara>Maximum number of total bytes in the dead letter queue from all messages.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqMaxPriority</term>
|
|
<listitem>
|
|
<simpara>Maximum priority of messages in the dead letter queue (0-255)
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>dlqTtl</term>
|
|
<listitem>
|
|
<simpara>Default time (in milliseconds) to live to apply to the dead letter queue when declared.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeAutoDelete</term>
|
|
<listitem>
|
|
<simpara>If <literal>declareExchange</literal> is <literal>true</literal>, whether the exchange should be auto-delete (it is removed after the last queue is removed).</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeDurable</term>
|
|
<listitem>
|
|
<simpara>If <literal>declareExchange</literal> is <literal>true</literal>, whether the exchange should be durable (survives broker restart).</simpara>
|
|
<simpara>Default: <literal>true</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>exchangeType</term>
|
|
<listitem>
|
|
<simpara>The exchange type: <literal>direct</literal>, <literal>fanout</literal> or <literal>topic</literal> for non-partitioned destinations and <literal>direct</literal> or <literal>topic</literal> for partitioned destinations.</simpara>
|
|
<simpara>Default: <literal>topic</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>expires</term>
|
|
<listitem>
|
|
<simpara>How long (in milliseconds) before an unused queue is deleted.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no expiration</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>headerPatterns</term>
|
|
<listitem>
|
|
<simpara>Patterns for headers to be mapped to outbound messages.</simpara>
|
|
<simpara>Default: <literal>['*']</literal> (all headers).</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>lazy</term>
|
|
<listitem>
|
|
<simpara>Declare the queue with the <literal>x-queue-mode=lazy</literal> argument.
|
|
See <link xl:href="https://www.rabbitmq.com/lazy-queues.html"><quote>Lazy Queues</quote></link>.
|
|
Consider using a policy instead of this setting, because using a policy allows changing the setting without deleting the queue.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxLength</term>
|
|
<listitem>
|
|
<simpara>Maximum number of messages in the queue.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxLengthBytes</term>
|
|
<listitem>
|
|
<simpara>Maximum number of total bytes in the queue from all messages.
|
|
Only applies if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>maxPriority</term>
|
|
<listitem>
|
|
<simpara>Maximum priority of messages in the queue (0-255).
|
|
Only applies if <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>none</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>prefix</term>
|
|
<listitem>
|
|
<simpara>A prefix to be added to the name of the <literal>destination</literal> exchange.</simpara>
|
|
<simpara>Default: "".</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>queueNameGroupOnly</term>
|
|
<listitem>
|
|
<simpara>When <literal>true</literal>, consume from a queue with a name equal to the <literal>group</literal>.
|
|
Otherwise the queue name is <literal>destination.group</literal>.
|
|
This is useful, for example, when using Spring Cloud Stream to consume from an existing RabbitMQ queue.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: false.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>routingKeyExpression</term>
|
|
<listitem>
|
|
<simpara>A SpEL expression to determine the routing key to use when publishing messages.
|
|
For a fixed routing key, use a literal expression, such as <literal>routingKeyExpression='my.routingKey'</literal> in a properties file or <literal>routingKeyExpression: '''my.routingKey'''</literal> in a YAML file.</simpara>
|
|
<simpara>Default: <literal>destination</literal> or <literal>destination-<partition></literal> for partitioned destinations.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>transacted</term>
|
|
<listitem>
|
|
<simpara>Whether to use transacted channels.</simpara>
|
|
<simpara>Default: <literal>false</literal>.</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>ttl</term>
|
|
<listitem>
|
|
<simpara>Default time (in milliseconds) to live to apply to the queue when declared.
|
|
Applies only when <literal>requiredGroups</literal> are provided and then only to those groups.</simpara>
|
|
<simpara>Default: <literal>no limit</literal></simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<note>
|
|
<simpara>In the case of RabbitMQ, content type headers can be set by external applications.
|
|
Spring Cloud Stream supports them as part of an extended internal protocol used for any type of transport — including transports, such as Kafka (prior to 0.11), that do not natively support headers.</simpara>
|
|
</note>
|
|
</section>
|
|
</chapter>
|
|
<chapter xml:id="_retry_with_the_rabbitmq_binder">
|
|
<title>Retry With the RabbitMQ Binder</title>
|
|
<simpara>When retry is enabled within the binder, the listener container thread is suspended for any back off periods that are configured.
|
|
This might be important when strict ordering is required with a single consumer. However, for other use cases, it prevents other messages from being processed on that thread.
|
|
An alternative to using binder retry is to set up dead lettering with time to live on the dead-letter queue (DLQ) as well as dead-letter configuration on the DLQ itself.
|
|
See <quote><xref linkend="rabbit-binder-properties"/></quote> for more information about the properties discussed here.
|
|
You can use the following example configuration to enable this feature:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>Set <literal>autoBindDlq</literal> to <literal>true</literal>.
|
|
The binder create a DLQ.
|
|
Optionally, you can specify a name in <literal>deadLetterQueueName</literal>.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Set <literal>dlqTtl</literal> to the back off time you want to wait between redeliveries.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Set the <literal>dlqDeadLetterExchange</literal> to the default exchange.
|
|
Expired messages from the DLQ are routed to the original queue, because the default <literal>deadLetterRoutingKey</literal> is the queue name (<literal>destination.group</literal>).
|
|
Setting to the default exchange is achieved by setting the property with no value, as shown in the next example.</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>To force a message to be dead-lettered, either throw an <literal>AmqpRejectAndDontRequeueException</literal> or set <literal>requeueRejected</literal> to <literal>true</literal> (the default) and throw any exception.</simpara>
|
|
<simpara>The loop continue without end, which is fine for transient problems, but you may want to give up after some number of attempts.
|
|
Fortunately, RabbitMQ provides the <literal>x-death</literal> header, which lets you determine how many cycles have occurred.</simpara>
|
|
<simpara>To acknowledge a message after giving up, throw an <literal>ImmediateAcknowledgeAmqpException</literal>.</simpara>
|
|
<section xml:id="_putting_it_all_together">
|
|
<title>Putting it All Together</title>
|
|
<simpara>The following configuration creates an exchange <literal>myDestination</literal> with queue <literal>myDestination.consumerGroup</literal> bound to a topic exchange with a wildcard routing key <literal>#</literal>:</simpara>
|
|
<screen>---
|
|
spring.cloud.stream.bindings.input.destination=myDestination
|
|
spring.cloud.stream.bindings.input.group=consumerGroup
|
|
#disable binder retries
|
|
spring.cloud.stream.bindings.input.consumer.max-attempts=1
|
|
#dlx/dlq setup
|
|
spring.cloud.stream.rabbit.bindings.input.consumer.auto-bind-dlq=true
|
|
spring.cloud.stream.rabbit.bindings.input.consumer.dlq-ttl=5000
|
|
spring.cloud.stream.rabbit.bindings.input.consumer.dlq-dead-letter-exchange=
|
|
---</screen>
|
|
<simpara>This configuration creates a DLQ bound to a direct exchange (<literal>DLX</literal>) with a routing key of <literal>myDestination.consumerGroup</literal>.
|
|
When messages are rejected, they are routed to the DLQ.
|
|
After 5 seconds, the message expires and is routed to the original queue by using the queue name as the routing key, as shown in the following example:</simpara>
|
|
<formalpara>
|
|
<title>Spring Boot application</title>
|
|
<para>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
@EnableBinding(Sink.class)
|
|
public class XDeathApplication {
|
|
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(XDeathApplication.class, args);
|
|
}
|
|
|
|
@StreamListener(Sink.INPUT)
|
|
public void listen(String in, @Header(name = "x-death", required = false) Map<?,?> death) {
|
|
if (death != null && death.get("count").equals(3L)) {
|
|
// giving up - don't send to DLX
|
|
throw new ImmediateAcknowledgeAmqpException("Failed after 4 attempts");
|
|
}
|
|
throw new AmqpRejectAndDontRequeueException("failed");
|
|
}
|
|
|
|
}</programlisting>
|
|
</para>
|
|
</formalpara>
|
|
<simpara>Notice that the count property in the <literal>x-death</literal> header is a <literal>Long</literal>.</simpara>
|
|
</section>
|
|
</chapter>
|
|
<chapter xml:id="rabbit-error-channels">
|
|
<title>Error Channels</title>
|
|
<simpara>Starting with version 1.3, the binder unconditionally sends exceptions to an error channel for each consumer destination and can also be configured to send async producer send failures to an error channel.
|
|
See <quote><xref linkend="binder-error-channels"/></quote> for more information.</simpara>
|
|
<simpara>RabbitMQ has two types of send failures:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>Returned messages,</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Negatively acknowledged <link xl:href="https://www.rabbitmq.com/confirms.html">Publisher Confirms</link>.</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>The latter is rare.
|
|
According to the RabbitMQ documentation "[A nack] will only be delivered if an internal error occurs in the Erlang process responsible for a queue.".</simpara>
|
|
<simpara>As well as enabling producer error channels (as described in <quote><xref linkend="binder-error-channels"/></quote>), the RabbitMQ binder only sends messages to the channels if the connection factory is appropriately configured, as follows:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><literal>ccf.setPublisherConfirms(true);</literal></simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>ccf.setPublisherReturns(true);</literal></simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>When using Spring Boot configuration for the connection factory, set the following properties:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><literal>spring.rabbitmq.publisher-confirms</literal></simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>spring.rabbitmq.publisher-returns</literal></simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>The payload of the <literal>ErrorMessage</literal> for a returned message is a <literal>ReturnedAmqpMessageException</literal> with the following properties:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><literal>failedMessage</literal>: The spring-messaging <literal>Message<?></literal> that failed to be sent.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>amqpMessage</literal>: The raw spring-amqp <literal>Message</literal>.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>replyCode</literal>: An integer value indicating the reason for the failure (for example, 312 - No route).</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>replyText</literal>: A text value indicating the reason for the failure (for example, <literal>NO_ROUTE</literal>).</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>exchange</literal>: The exchange to which the message was published.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>routingKey</literal>: The routing key used when the message was published.</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>For negatively acknowledged confirmations, the payload is a <literal>NackedAmqpMessageException</literal> with the following properties:</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><literal>failedMessage</literal>: The spring-messaging <literal>Message<?></literal> that failed to be sent.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><literal>nackReason</literal>: A reason (if available — you may need to examine the broker logs for more information).</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
<simpara>There is no automatic handling of these exceptions (such as sending to a <link linkend="rabbit-dlq-processing">dead-letter queue</link>).
|
|
You can consume these exceptions with your own Spring Integration flow.</simpara>
|
|
</chapter>
|
|
<chapter xml:id="rabbit-dlq-processing">
|
|
<title>Dead-Letter Queue Processing</title>
|
|
<simpara>Because you cannot anticipate how users would want to dispose of dead-lettered messages, the framework does not provide any standard mechanism to handle them.
|
|
If the reason for the dead-lettering is transient, you may wish to route the messages back to the original queue.
|
|
However, if the problem is a permanent issue, that could cause an infinite loop.
|
|
The following Spring Boot application shows an example of how to route those messages back to the original queue but moves them to a third <quote>parking lot</quote> queue after three attempts.
|
|
The second example uses the <link xl:href="https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq/">RabbitMQ Delayed Message Exchange</link> to introduce a delay to the re-queued message.
|
|
In this example, the delay increases for each attempt.
|
|
These examples use a <literal>@RabbitListener</literal> to receive messages from the DLQ.
|
|
You could also use <literal>RabbitTemplate.receive()</literal> in a batch process.</simpara>
|
|
<simpara>The examples assume the original destination is <literal>so8400in</literal> and the consumer group is <literal>so8400</literal>.</simpara>
|
|
<section xml:id="_non_partitioned_destinations">
|
|
<title>Non-Partitioned Destinations</title>
|
|
<simpara>The first two examples are for when the destination is <emphasis role="strong">not</emphasis> partitioned:</simpara>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
public class ReRouteDlqApplication {
|
|
|
|
private static final String ORIGINAL_QUEUE = "so8400in.so8400";
|
|
|
|
private static final String DLQ = ORIGINAL_QUEUE + ".dlq";
|
|
|
|
private static final String PARKING_LOT = ORIGINAL_QUEUE + ".parkingLot";
|
|
|
|
private static final String X_RETRIES_HEADER = "x-retries";
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
ConfigurableApplicationContext context = SpringApplication.run(ReRouteDlqApplication.class, args);
|
|
System.out.println("Hit enter to terminate");
|
|
System.in.read();
|
|
context.close();
|
|
}
|
|
|
|
@Autowired
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
@RabbitListener(queues = DLQ)
|
|
public void rePublish(Message failedMessage) {
|
|
Integer retriesHeader = (Integer) failedMessage.getMessageProperties().getHeaders().get(X_RETRIES_HEADER);
|
|
if (retriesHeader == null) {
|
|
retriesHeader = Integer.valueOf(0);
|
|
}
|
|
if (retriesHeader < 3) {
|
|
failedMessage.getMessageProperties().getHeaders().put(X_RETRIES_HEADER, retriesHeader + 1);
|
|
this.rabbitTemplate.send(ORIGINAL_QUEUE, failedMessage);
|
|
}
|
|
else {
|
|
this.rabbitTemplate.send(PARKING_LOT, failedMessage);
|
|
}
|
|
}
|
|
|
|
@Bean
|
|
public Queue parkingLot() {
|
|
return new Queue(PARKING_LOT);
|
|
}
|
|
|
|
}</programlisting>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
public class ReRouteDlqApplication {
|
|
|
|
private static final String ORIGINAL_QUEUE = "so8400in.so8400";
|
|
|
|
private static final String DLQ = ORIGINAL_QUEUE + ".dlq";
|
|
|
|
private static final String PARKING_LOT = ORIGINAL_QUEUE + ".parkingLot";
|
|
|
|
private static final String X_RETRIES_HEADER = "x-retries";
|
|
|
|
private static final String DELAY_EXCHANGE = "dlqReRouter";
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
ConfigurableApplicationContext context = SpringApplication.run(ReRouteDlqApplication.class, args);
|
|
System.out.println("Hit enter to terminate");
|
|
System.in.read();
|
|
context.close();
|
|
}
|
|
|
|
@Autowired
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
@RabbitListener(queues = DLQ)
|
|
public void rePublish(Message failedMessage) {
|
|
Map<String, Object> headers = failedMessage.getMessageProperties().getHeaders();
|
|
Integer retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
|
|
if (retriesHeader == null) {
|
|
retriesHeader = Integer.valueOf(0);
|
|
}
|
|
if (retriesHeader < 3) {
|
|
headers.put(X_RETRIES_HEADER, retriesHeader + 1);
|
|
headers.put("x-delay", 5000 * retriesHeader);
|
|
this.rabbitTemplate.send(DELAY_EXCHANGE, ORIGINAL_QUEUE, failedMessage);
|
|
}
|
|
else {
|
|
this.rabbitTemplate.send(PARKING_LOT, failedMessage);
|
|
}
|
|
}
|
|
|
|
@Bean
|
|
public DirectExchange delayExchange() {
|
|
DirectExchange exchange = new DirectExchange(DELAY_EXCHANGE);
|
|
exchange.setDelayed(true);
|
|
return exchange;
|
|
}
|
|
|
|
@Bean
|
|
public Binding bindOriginalToDelay() {
|
|
return BindingBuilder.bind(new Queue(ORIGINAL_QUEUE)).to(delayExchange()).with(ORIGINAL_QUEUE);
|
|
}
|
|
|
|
@Bean
|
|
public Queue parkingLot() {
|
|
return new Queue(PARKING_LOT);
|
|
}
|
|
|
|
}</programlisting>
|
|
</section>
|
|
<section xml:id="_partitioned_destinations">
|
|
<title>Partitioned Destinations</title>
|
|
<simpara>With partitioned destinations, there is one DLQ for all partitions. We determine the original queue from the headers.</simpara>
|
|
<section xml:id="_republishtodlqfalse">
|
|
<title><literal>republishToDlq=false</literal></title>
|
|
<simpara>When <literal>republishToDlq</literal> is <literal>false</literal>, RabbitMQ publishes the message to the DLX/DLQ with an <literal>x-death</literal> header containing information about the original destination, as shown in the following example:</simpara>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
public class ReRouteDlqApplication {
|
|
|
|
private static final String ORIGINAL_QUEUE = "so8400in.so8400";
|
|
|
|
private static final String DLQ = ORIGINAL_QUEUE + ".dlq";
|
|
|
|
private static final String PARKING_LOT = ORIGINAL_QUEUE + ".parkingLot";
|
|
|
|
private static final String X_DEATH_HEADER = "x-death";
|
|
|
|
private static final String X_RETRIES_HEADER = "x-retries";
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
ConfigurableApplicationContext context = SpringApplication.run(ReRouteDlqApplication.class, args);
|
|
System.out.println("Hit enter to terminate");
|
|
System.in.read();
|
|
context.close();
|
|
}
|
|
|
|
@Autowired
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@RabbitListener(queues = DLQ)
|
|
public void rePublish(Message failedMessage) {
|
|
Map<String, Object> headers = failedMessage.getMessageProperties().getHeaders();
|
|
Integer retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
|
|
if (retriesHeader == null) {
|
|
retriesHeader = Integer.valueOf(0);
|
|
}
|
|
if (retriesHeader < 3) {
|
|
headers.put(X_RETRIES_HEADER, retriesHeader + 1);
|
|
List<Map<String, ?>> xDeath = (List<Map<String, ?>>) headers.get(X_DEATH_HEADER);
|
|
String exchange = (String) xDeath.get(0).get("exchange");
|
|
List<String> routingKeys = (List<String>) xDeath.get(0).get("routing-keys");
|
|
this.rabbitTemplate.send(exchange, routingKeys.get(0), failedMessage);
|
|
}
|
|
else {
|
|
this.rabbitTemplate.send(PARKING_LOT, failedMessage);
|
|
}
|
|
}
|
|
|
|
@Bean
|
|
public Queue parkingLot() {
|
|
return new Queue(PARKING_LOT);
|
|
}
|
|
|
|
}</programlisting>
|
|
</section>
|
|
<section xml:id="_republishtodlqtrue">
|
|
<title><literal>republishToDlq=true</literal></title>
|
|
<simpara>When <literal>republishToDlq</literal> is <literal>true</literal>, the republishing recoverer adds the original exchange and routing key to headers, as shown in the following example:</simpara>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
public class ReRouteDlqApplication {
|
|
|
|
private static final String ORIGINAL_QUEUE = "so8400in.so8400";
|
|
|
|
private static final String DLQ = ORIGINAL_QUEUE + ".dlq";
|
|
|
|
private static final String PARKING_LOT = ORIGINAL_QUEUE + ".parkingLot";
|
|
|
|
private static final String X_RETRIES_HEADER = "x-retries";
|
|
|
|
private static final String X_ORIGINAL_EXCHANGE_HEADER = RepublishMessageRecoverer.X_ORIGINAL_EXCHANGE;
|
|
|
|
private static final String X_ORIGINAL_ROUTING_KEY_HEADER = RepublishMessageRecoverer.X_ORIGINAL_ROUTING_KEY;
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
ConfigurableApplicationContext context = SpringApplication.run(ReRouteDlqApplication.class, args);
|
|
System.out.println("Hit enter to terminate");
|
|
System.in.read();
|
|
context.close();
|
|
}
|
|
|
|
@Autowired
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
@RabbitListener(queues = DLQ)
|
|
public void rePublish(Message failedMessage) {
|
|
Map<String, Object> headers = failedMessage.getMessageProperties().getHeaders();
|
|
Integer retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
|
|
if (retriesHeader == null) {
|
|
retriesHeader = Integer.valueOf(0);
|
|
}
|
|
if (retriesHeader < 3) {
|
|
headers.put(X_RETRIES_HEADER, retriesHeader + 1);
|
|
String exchange = (String) headers.get(X_ORIGINAL_EXCHANGE_HEADER);
|
|
String originalRoutingKey = (String) headers.get(X_ORIGINAL_ROUTING_KEY_HEADER);
|
|
this.rabbitTemplate.send(exchange, originalRoutingKey, failedMessage);
|
|
}
|
|
else {
|
|
this.rabbitTemplate.send(PARKING_LOT, failedMessage);
|
|
}
|
|
}
|
|
|
|
@Bean
|
|
public Queue parkingLot() {
|
|
return new Queue(PARKING_LOT);
|
|
}
|
|
|
|
}</programlisting>
|
|
</section>
|
|
</section>
|
|
</chapter>
|
|
<chapter xml:id="_partitioning_with_the_rabbitmq_binder">
|
|
<title>Partitioning with the RabbitMQ Binder</title>
|
|
<simpara>RabbitMQ does not support partitioning natively.</simpara>
|
|
<simpara>Sometimes, it is advantageous to send data to specific partitions — for example, when you want to strictly order message processing, all messages for a particular customer should go to the same partition.</simpara>
|
|
<simpara>The <literal>RabbitMessageChannelBinder</literal> provides partitioning by binding a queue for each partition to the destination exchange.</simpara>
|
|
<simpara>The following Java and YAML examples show how to configure the producer:</simpara>
|
|
<formalpara>
|
|
<title>Producer</title>
|
|
<para>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
@EnableBinding(Source.class)
|
|
public class RabbitPartitionProducerApplication {
|
|
|
|
private static final Random RANDOM = new Random(System.currentTimeMillis());
|
|
|
|
private static final String[] data = new String[] {
|
|
"abc1", "def1", "qux1",
|
|
"abc2", "def2", "qux2",
|
|
"abc3", "def3", "qux3",
|
|
"abc4", "def4", "qux4",
|
|
};
|
|
|
|
public static void main(String[] args) {
|
|
new SpringApplicationBuilder(RabbitPartitionProducerApplication.class)
|
|
.web(false)
|
|
.run(args);
|
|
}
|
|
|
|
@InboundChannelAdapter(channel = Source.OUTPUT, poller = @Poller(fixedRate = "5000"))
|
|
public Message<?> generate() {
|
|
String value = data[RANDOM.nextInt(data.length)];
|
|
System.out.println("Sending: " + value);
|
|
return MessageBuilder.withPayload(value)
|
|
.setHeader("partitionKey", value)
|
|
.build();
|
|
}
|
|
|
|
}</programlisting>
|
|
</para>
|
|
</formalpara>
|
|
<formalpara>
|
|
<title>application.yml</title>
|
|
<para>
|
|
<programlisting language="yaml" linenumbering="unnumbered"> spring:
|
|
cloud:
|
|
stream:
|
|
bindings:
|
|
output:
|
|
destination: partitioned.destination
|
|
producer:
|
|
partitioned: true
|
|
partition-key-expression: headers['partitionKey']
|
|
partition-count: 2
|
|
required-groups:
|
|
- myGroup</programlisting>
|
|
</para>
|
|
</formalpara>
|
|
<note>
|
|
<simpara>The configuration in the prececing example uses the default partitioning (<literal>key.hashCode() % partitionCount</literal>).
|
|
This may or may not provide a suitably balanced algorithm, depending on the key values.
|
|
You can override this default by using the <literal>partitionSelectorExpression</literal> or <literal>partitionSelectorClass</literal> properties.</simpara>
|
|
<simpara>The <literal>required-groups</literal> property is required only if you need the consumer queues to be provisioned when the producer is deployed.
|
|
Otherwise, any messages sent to a partition are lost until the corresponding consumer is deployed.</simpara>
|
|
</note>
|
|
<simpara>The following configuration provisions a topic exchange:</simpara>
|
|
<informalfigure>
|
|
<mediaobject>
|
|
<imageobject>
|
|
<imagedata fileref="images/part-exchange.png" width="50%"/>
|
|
</imageobject>
|
|
<textobject><phrase>part exchange</phrase></textobject>
|
|
</mediaobject>
|
|
</informalfigure>
|
|
<simpara>The following queues are bound to that exchange:</simpara>
|
|
<informalfigure>
|
|
<mediaobject>
|
|
<imageobject>
|
|
<imagedata fileref="images/part-queues.png" width="50%"/>
|
|
</imageobject>
|
|
<textobject><phrase>part queues</phrase></textobject>
|
|
</mediaobject>
|
|
</informalfigure>
|
|
<simpara>The following bindings associate the queues to the exchange:</simpara>
|
|
<informalfigure>
|
|
<mediaobject>
|
|
<imageobject>
|
|
<imagedata fileref="images/part-bindings.png" width="50%"/>
|
|
</imageobject>
|
|
<textobject><phrase>part bindings</phrase></textobject>
|
|
</mediaobject>
|
|
</informalfigure>
|
|
<simpara>The following Java and YAML examples continue the previous examples and show how to configure the consumer:</simpara>
|
|
<formalpara>
|
|
<title>Consumer</title>
|
|
<para>
|
|
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
|
|
@EnableBinding(Sink.class)
|
|
public class RabbitPartitionConsumerApplication {
|
|
|
|
public static void main(String[] args) {
|
|
new SpringApplicationBuilder(RabbitPartitionConsumerApplication.class)
|
|
.web(false)
|
|
.run(args);
|
|
}
|
|
|
|
@StreamListener(Sink.INPUT)
|
|
public void listen(@Payload String in, @Header(AmqpHeaders.CONSUMER_QUEUE) String queue) {
|
|
System.out.println(in + " received from queue " + queue);
|
|
}
|
|
|
|
}</programlisting>
|
|
</para>
|
|
</formalpara>
|
|
<formalpara>
|
|
<title>application.yml</title>
|
|
<para>
|
|
<programlisting language="yaml" linenumbering="unnumbered"> spring:
|
|
cloud:
|
|
stream:
|
|
bindings:
|
|
input:
|
|
destination: partitioned.destination
|
|
group: myGroup
|
|
consumer:
|
|
partitioned: true
|
|
instance-index: 0</programlisting>
|
|
</para>
|
|
</formalpara>
|
|
<important>
|
|
<simpara>The <literal>RabbitMessageChannelBinder</literal> does not support dynamic scaling.
|
|
There must be at least one consumer per partition.
|
|
The consumer’s <literal>instanceIndex</literal> is used to indicate which partition is consumed.
|
|
Platforms such as Cloud Foundry can have only one instance with an <literal>instanceIndex</literal>.</simpara>
|
|
</important>
|
|
</chapter>
|
|
</part>
|
|
<part xml:id="_appendices">
|
|
<title>Appendices</title>
|
|
<appendix xml:id="building">
|
|
<title>Building</title>
|
|
<section xml:id="_basic_compile_and_test">
|
|
<title>Basic Compile and Test</title>
|
|
<simpara>To build the source you will need to install JDK 1.8.</simpara>
|
|
<simpara>The build uses the Maven wrapper so you don’t have to install a specific
|
|
version of Maven. To enable the tests, you should have RabbitMQ server running
|
|
on localhost and the default port (5672)
|
|
before building.</simpara>
|
|
<simpara>The main build command is</simpara>
|
|
<screen>$ ./mvnw clean install</screen>
|
|
<simpara>You can also add '-DskipTests' if you like, to avoid running the tests.</simpara>
|
|
<note>
|
|
<simpara>You can also install Maven (>=3.3.3) yourself and run the <literal>mvn</literal> command
|
|
in place of <literal>./mvnw</literal> in the examples below. If you do that you also
|
|
might need to add <literal>-P spring</literal> if your local Maven settings do not
|
|
contain repository declarations for spring pre-release artifacts.</simpara>
|
|
</note>
|
|
<note>
|
|
<simpara>Be aware that you might need to increase the amount of memory
|
|
available to Maven by setting a <literal>MAVEN_OPTS</literal> environment variable with
|
|
a value like <literal>-Xmx512m -XX:MaxPermSize=128m</literal>. We try to cover this in
|
|
the <literal>.mvn</literal> configuration, so if you find you have to do it to make a
|
|
build succeed, please raise a ticket to get the settings added to
|
|
source control.</simpara>
|
|
</note>
|
|
<simpara>The projects that require middleware generally include a
|
|
<literal>docker-compose.yml</literal>, so consider using
|
|
<link xl:href="https://compose.docker.io/">Docker Compose</link> to run the middeware servers
|
|
in Docker containers.</simpara>
|
|
</section>
|
|
<section xml:id="_documentation">
|
|
<title>Documentation</title>
|
|
<simpara>There is a "full" profile that will generate documentation.</simpara>
|
|
</section>
|
|
<section xml:id="_working_with_the_code">
|
|
<title>Working with the code</title>
|
|
<simpara>If you don’t have an IDE preference we would recommend that you use
|
|
<link xl:href="https://www.springsource.com/developer/sts">Spring Tools Suite</link> or
|
|
<link xl:href="https://eclipse.org">Eclipse</link> when working with the code. We use the
|
|
<link xl:href="https://eclipse.org/m2e/">m2eclipe</link> eclipse plugin for maven support. Other IDEs and tools
|
|
should also work without issue.</simpara>
|
|
<section xml:id="_importing_into_eclipse_with_m2eclipse">
|
|
<title>Importing into eclipse with m2eclipse</title>
|
|
<simpara>We recommend the <link xl:href="https://eclipse.org/m2e/">m2eclipe</link> eclipse plugin when working with
|
|
eclipse. If you don’t already have m2eclipse installed it is available from the "eclipse
|
|
marketplace".</simpara>
|
|
<simpara>Unfortunately m2e does not yet support Maven 3.3, so once the projects
|
|
are imported into Eclipse you will also need to tell m2eclipse to use
|
|
the <literal>.settings.xml</literal> file for the projects. If you do not do this you
|
|
may see many different errors related to the POMs in the
|
|
projects. Open your Eclipse preferences, expand the Maven
|
|
preferences, and select User Settings. In the User Settings field
|
|
click Browse and navigate to the Spring Cloud project you imported
|
|
selecting the <literal>.settings.xml</literal> file in that project. Click Apply and
|
|
then OK to save the preference changes.</simpara>
|
|
<note>
|
|
<simpara>Alternatively you can copy the repository settings from <link xl:href="https://github.com/spring-cloud/spring-cloud-build/blob/master/.settings.xml"><literal>.settings.xml</literal></link> into your own <literal>~/.m2/settings.xml</literal>.</simpara>
|
|
</note>
|
|
</section>
|
|
<section xml:id="_importing_into_eclipse_without_m2eclipse">
|
|
<title>Importing into eclipse without m2eclipse</title>
|
|
<simpara>If you prefer not to use m2eclipse you can generate eclipse project metadata using the
|
|
following command:</simpara>
|
|
<screen>$ ./mvnw eclipse:eclipse</screen>
|
|
<simpara>The generated eclipse projects can be imported by selecting <literal>import existing projects</literal>
|
|
from the <literal>file</literal> menu.</simpara>
|
|
</section>
|
|
</section>
|
|
</appendix>
|
|
<appendix xml:id="contributing">
|
|
<title>Contributing</title>
|
|
<simpara>Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
|
and follows a very standard Github development process, using Github
|
|
tracker for issues and merging pull requests into master. If you want
|
|
to contribute even something trivial please do not hesitate, but
|
|
follow the guidelines below.</simpara>
|
|
<section xml:id="_sign_the_contributor_license_agreement">
|
|
<title>Sign the Contributor License Agreement</title>
|
|
<simpara>Before we accept a non-trivial patch or pull request we will need you to sign the
|
|
<link xl:href="https://support.springsource.com/spring_committer_signup">contributor’s agreement</link>.
|
|
Signing the contributor’s agreement does not grant anyone commit rights to the main
|
|
repository, but it does mean that we can accept your contributions, and you will get an
|
|
author credit if we do. Active contributors might be asked to join the core team, and
|
|
given the ability to merge pull requests.</simpara>
|
|
</section>
|
|
<section xml:id="_code_conventions_and_housekeeping">
|
|
<title>Code Conventions and Housekeeping</title>
|
|
<simpara>None of these is essential for a pull request, but they will all help. They can also be
|
|
added after the original pull request but before a merge.</simpara>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>Use the Spring Framework code format conventions. If you use Eclipse
|
|
you can import formatter settings using the
|
|
<literal>eclipse-code-formatter.xml</literal> file from the
|
|
<link xl:href="https://github.com/spring-cloud/build/tree/master/eclipse-coding-conventions.xml">Spring
|
|
Cloud Build</link> project. If using IntelliJ, you can use the
|
|
<link xl:href="https://plugins.jetbrains.com/plugin/6546">Eclipse Code Formatter
|
|
Plugin</link> to import the same file.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Make sure all new <literal>.java</literal> files to have a simple Javadoc class comment with at least an
|
|
<literal>@author</literal> tag identifying you, and preferably at least a paragraph on what the class is
|
|
for.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Add the ASF license header comment to all new <literal>.java</literal> files (copy from existing files
|
|
in the project)</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Add yourself as an <literal>@author</literal> to the .java files that you modify substantially (more
|
|
than cosmetic changes).</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>Add some Javadocs and, if you change the namespace, some XSD doc elements.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>A few unit tests would help a lot as well — someone has to do it.</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>If no-one else is using your branch, please rebase it against the current master (or
|
|
other target branch in the main project).</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>When writing a commit message please follow <link xl:href="https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html">these conventions</link>,
|
|
if you are fixing an existing issue please add <literal>Fixes gh-XXXX</literal> at the end of the commit
|
|
message (where XXXX is the issue number).</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</section>
|
|
</appendix>
|
|
</part>
|
|
</book> |