GH-325: Initial Support for RabbitMQ Stream Plugin
Resolves https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/325 * Do not propagate `streamContext` header on output. * Fix test broken by previous commit. * Remove overrides from POMs.
This commit is contained in:
@@ -164,6 +164,7 @@ Default: none - the broker will generate random consumer tags.
|
||||
containerType::
|
||||
Select the type of listener container to be used.
|
||||
See https://docs.spring.io/spring-amqp/reference/html/_reference.html#choose-container[Choosing a Container] in the Spring AMQP documentation for more information.
|
||||
Also see <<rabbitmq-stream>>.
|
||||
+
|
||||
Default: `simple`
|
||||
deadLetterQueueName::
|
||||
@@ -413,6 +414,62 @@ Not supported when the `containerType` is `direct`.
|
||||
+
|
||||
Default: `1`.
|
||||
|
||||
[[rabbitmq-stream]]
|
||||
=== Initial Support for the RabbitMQ Stream Plugin
|
||||
|
||||
Basic support for the https://rabbitmq.com/stream.html[RabbitMQ Stream Plugin] is now provided.
|
||||
To enable this feature, you must add the `spring-rabbit-stream` jar to the class path - it must be the same version as `spring-amqp` and `spring-rabbit`.
|
||||
|
||||
IMPORTANT: The consumer properties described above are not supported when you set the `containerType` property to `stream`; `concurrency` is also not supported at this time.
|
||||
Only a single stream queue can be consumed by each binding.
|
||||
|
||||
To configure the binder to use `containerType=stream`, you must add an `Environment` `@Bean` and, optionally, a customizer to customize the listener container.
|
||||
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
@Bean
|
||||
Environment streamEnv() {
|
||||
return Environment.builder()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
ListenerContainerCustomizer<MessageListenerContainer> customizer() {
|
||||
return (cont, dest, group) -> {
|
||||
StreamListenerContainer container = (StreamListenerContainer) cont;
|
||||
container.setConsumerCustomizer(builder -> {
|
||||
builder.offset(OffsetSpecification.first());
|
||||
});
|
||||
// ...
|
||||
};
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
The stream name (for the purpose of offset tracking) is set to the binding `destination + '.' + group`.
|
||||
If you decide to use manual offset tracking, the `Context` is available as a message header:
|
||||
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
int count;
|
||||
|
||||
@Bean
|
||||
public Consumer<Message<?>> input() {
|
||||
return msg -> {
|
||||
System.out.println(msg);
|
||||
if (++count % 1000 == 0) {
|
||||
Context context = msg.getHeaders().get("rabbitmq_streamContext", Context.class);
|
||||
context.consumer().store(context.offset());
|
||||
}
|
||||
};
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
Refer to the https://rabbitmq.github.io/rabbitmq-stream-java-client/stable/htmlsingle/[RabbitMQ Stream Java Client documentation] for information about configuring the environment and consumer builder.
|
||||
|
||||
=== Advanced Listener Container Configuration
|
||||
|
||||
To set listener container properties that are not exposed as binder or binding properties, add a single bean of type `ListenerContainerCustomizer` to the application context.
|
||||
|
||||
Reference in New Issue
Block a user