diff --git a/docs/src/reference/docbook/channel.xml b/docs/src/reference/docbook/channel.xml index e91179d207..aac3439e0f 100644 --- a/docs/src/reference/docbook/channel.xml +++ b/docs/src/reference/docbook/channel.xml @@ -377,17 +377,6 @@ public Message receive(final PollableChannel channel) { ... }]]>Publish Subscribe channel, use the <publish-subscribe-channel/> element: <publish-subscribe-channel id="exampleChannel"/> - - To create a Datatype Channel that only - accepts messages containing a certain payload type, provide the fully-qualified class name in the - channel element's datatype attribute: - ]]> - Note that the type check passes for any type that is assignable to the channel's - datatype. In other words, the "numberChannel" above would accept messages whose payload is - java.lang.Integer or java.lang.Double. Multiple types can be - provided as a comma-delimited list: - ]]> - When using the <channel/> element without any sub-elements, it will create a DirectChannel instance (a SubscribableChannel). @@ -419,6 +408,65 @@ public Message receive(final PollableChannel channel) { ... }]]> +
+ Datatype Channel Configuration + + There are times when a consumer can only process a particular type of payload and you need to ensure the payload type of the input Message. + Of course the first thing that comes to mind is Message Filter. However all that Message Filter will do is filter out Messages that are not compliant with + the requirements of the consumer. Another way would be to use a Content Based Routing and route Messages with incompliant data-type to specific + Transformers to ensure transformation/conversion to the required data-type. This of course would work, but there is a simpler way of accomplishing this if + you apply Datatype Channel pattern. + You can use separate Datatype Channel for a specific data-type of the payload. + + + To create a Datatype Channel that only + accepts messages containing a certain payload type, provide the fully-qualified class name in the + channel element's datatype attribute: + + ]]> + + Note that the type check passes for any type that is assignable to the channel's + datatype. In other words, the "numberChannel" above would accept messages whose payload is + java.lang.Integer or java.lang.Double. Multiple types can be + provided as a comma-delimited list: + ]]> + + + So the 'numberChannel' above will only accept Messages with data-type of java.lang.Number regardless of what was + the payload type of the Message that was sent to this channel. But what happens if the payload of the Message is not of the required type? + In this case the Datatype Channel will attempt to convert the type of the payload to the required type using Spring's + Conversion Service where + you can register custom converters. For example: + + + Let's say you are sending a Message with a String payload to the 'numberChannel' we configured above. + ("5")); + ]]> + + Typically this would be a perfectly legal operation, however since we are using Datatype Channel the result of such operation will be exception: + + + And rightfully so since we are requiring the payload type to be a Number while sending a String. So we need something to convert String to a Number. +All we need to do is implement a Converter + { + public Integer convert(String source) { + return Integer.parseInt(source); + } +}]]> +Register it as a converter with Integration Conversion Service + + +]]> +And now the send operation will be successful since our Datatype Channel will use this converter to convert String to Integer. + + +
QueueChannel Configuration