From d21b42dbcf825772a4071520529d906bdb5a732d Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 8 Oct 2015 17:56:08 -0400 Subject: [PATCH] Java & DSL Config for the `QueueChannel` Also fix some typos in the `mongodb.adoc` --- src/reference/asciidoc/channel.adoc | 32 +++++++++++++++++++++++++++++ src/reference/asciidoc/mongodb.adoc | 8 ++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/reference/asciidoc/channel.adoc b/src/reference/asciidoc/channel.adoc index 89b1a93e11..edf88dd838 100644 --- a/src/reference/asciidoc/channel.adoc +++ b/src/reference/asciidoc/channel.adoc @@ -505,6 +505,38 @@ Since _version 4.0_, it is recommended that `QueueChannel` s are configured to u These are generally optimized for this use, when compared with a general message store. If the `ChannelMessageStore` is a `ChannelPriorityMessageStore` the messages will be received in FIFO within priority order. The notion of priority is determined by the message store implementation. +For example the Java Configuration for the <>: + +[source,java] +---- +@Bean +public BasicMessageGroupStore mongoDbChannelMessageStore(MongoDbFactory mongoDbFactory) { + MongoDbChannelMessageStore store = new MongoDbChannelMessageStore(mongoDbFactory); + store.setPriorityEnabled(true); + return store; +} + +@Bean +public PollableChannel priorityQueue(BasicMessageGroupStore mongoDbChannelMessageStore) { + return new QueueChannel(new MessageGroupQueue(mongoDbChannelMessageStore, "priorityQueue")); +} +---- + +NOTE: Pay attention to the `MessageGroupQueue` class. +That is a `BlockingQueue` implementation to utilize the `MessageGroupStore` operations. + +The same with Java DSL may look like: + +[source,java] +---- +@Bean +public IntegrationFlow priorityFlow(PriorityCapableChannelMessageStore mongoDbChannelMessageStore) { + return IntegrationFlows.from((Channels c) -> + c.priority("priorityChannel", mongoDbChannelMessageStore, "priorityGroup")) + .... + .get(); +} +---- Another option to customize the QueueChannel environment is provided by the `ref` attribute of the `` sub-element. This attribute implies the reference to any `java.util.Queue` implementation. diff --git a/src/reference/asciidoc/mongodb.adoc b/src/reference/asciidoc/mongodb.adoc index a5f0d65616..0b860a6c84 100644 --- a/src/reference/asciidoc/mongodb.adoc +++ b/src/reference/asciidoc/mongodb.adoc @@ -107,11 +107,11 @@ The default name for the collection stored by the `ConfigurableMongoDbMessageSto It is recommended to use this implementation for robust and flexible solutions when messages contain complex data types. [[mongodb-priority-channel-message-store]] -==== MongodDB Channel Message Store +==== MongoDB Channel Message Store Starting with _version 4.0_, the new `MongoDbChannelMessageStore` has been introduced; it is an optimized `MessageGroupStore` for use in `QueueChannel` s. With `priorityEnabled = true`, it can be used in `` s to achieve _priority_ order polling for persisted messages. -The _priority_ MonogDB document field is populated from the `IntegrationMessageHeaderAccessor.PRIORITY` (`priority`) message header. +The _priority_ MongoDB document field is populated from the `IntegrationMessageHeaderAccessor.PRIORITY` (`priority`) message header. In addition, all MongoDB `MessageStore` s now have a `sequence` field for MessageGroup documents. The `sequence` value is the result of an `$inc` operation for a simple `sequence` document from the same collection, which is created on demand. @@ -141,9 +141,9 @@ To configure that scenario, simply extend one message store bean from the other: ---- [[mongodb-metadata-store]] -==== MongodDB Metadata Store +==== MongoDB Metadata Store -As of _Spring Integration 4.2_, a new MongodDB-based `MetadataStore` (<>) implementation is available. +As of _Spring Integration 4.2_, a new MongoDB-based `MetadataStore` (<>) implementation is available. The `MongoDbMetadataStore` can be used to maintain metadata state across application restarts. This new `MetadataStore` implementation can be used with adapters such as: