Spring Book – Chapter 20 – Spring Integration

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

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

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

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

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

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

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

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

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

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: 13313

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 20 – Spring Integration

  1. 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!

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *