Message Channel Types
Channels may be classified according to whether messages are delivered to a single endpoint as point-to-point or to any endpoint that is listening to the channel as publish-subscribe.
Point-to-Point
In Point-to-Point messaging for each message send by the producer has only one consumer. That means, only one receiver per message. Pictorially this messaging type can be represented as shown in Figure 22-4 below.
Figure 22-4. Point-to-Point message channel
Point-to-Point messaging can be categorized into two types:
- DirectChannel
- QueueChannel
DirectChannel
It’s a Point-to-Point messaging in which the message from the sender (producer) is passed to the receiver (consumer) in the sender’s thread itself. This is synchronous in nature and because of this the sending blocks if the consumption doesn’t happen. Pictorially it is represented as shown in Figure 22-5 below.
Figure 22-5. Direct channel
Listing 22-1 below shows declaring DirectChannel (synchronous) in the Spring configuration file.
Listing 22-1. Declaring DirectChannel in Spring configuration file
1 |
<channel id=”incoming”/> |
QueueChannel
It’s a Point-to-Point messaging in which the message send by the sender gets queued and receiver in different threads polls the queue and consume the message. The message consumption is asynchronous in nature and because of this the sender is not blocked even though message consumption from the queue doesn’t happen. Pictorially it is represented as shown in Figure 22-6 below.
Figure 22-6. Queue channel
Listing 22-2 below shows declaring QueueChannel (asynchronous) in the Spring configuration file.
Listing 22-2. Declaring QueueChannel in Spring configuration file
1 2 3 4 5 |
<channel id=”emailNotifications”> <queue capacity=”5”/> </channel> |
Publish-subscribe
In Publish-Subscribe messaging the for each message send by the sender has multiple receivers. Pictorially this messaging type can be represented as shown in Figure 22-7 below.
Figure 22-7. Publish-Subscribe message channel
PublishSubscribeChannel is one such message channel.
PublishSubscribeChannel
PublishSubscribeChannel is one such message channel in which the receivers are invoked consecutively in sender’s thread or receivers are invoked in parallel on different threads using TaskExecutor. The first way is done in a synchronous way and the second way is done in asynchronous way. To have a consistent pictorial representation as shown earlier, this message channel can be represented as shown in Figure 22-8 below.
Figure 22-8. Publish-Subscribe channel
Listing 22-3 below shows declaring PublishSubscribeChannel (synchronous) in the Spring configuration file.
Listing 22-3. Declaring PublishSubscribeChannel in a synchronous manner in the Spring configuration file
1 |
<publish-subscribe-channel id=”logging”/> |
Listing 22-4 below shows declaring PublishSubscribeChannel (asynchronous) in the Spring configuration file.
Listing 22-4. Declaring PublishSubscribeChannel in an asynchronous maner in the Spring configuration file
1 2 3 |
<publish-subscribe-channel id=”emailNotifications” task-executor=”emailExecutor”/> <task:executor id=”emailExecutor” pool-size=”5”/> |
Note: TaskExecutor will be covered in Chapter 23, “Spring Batch”, having a section namely “Spring Integration and Spring Batch”, in which these concepts will be covered in detail.
Page Visitors: 13052


Tomcy John


Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu