Previous – Service Activator | Index | Next – Point-to-Point Channel
This week, we'll study a pattern known as
Message Channel.
When do I use this pattern?
Message Channel is a way to organise communication between two systems. When two systems want to talk, middleware is used. The middleware uses channels to receive messages and let other systems consume messages.
Message Channel in CPI
In CPI, I'll explore how to create a queue to represent a channel. For the demonstration, I'll fetch a product from Northwind OData Service and put it in a channel. Then, the product message will be consumed from the channel and logged into the message processing log.
Integration Flow - Fetch a Product
Fetch a Product
The integration flow starts immediately using a
Timer Start Event, fetches a product from Northwind Service using
OData Receiver Adapter, and sends it to 'Products' queue using
JMS Receiver Adapter.
The configuration of the
OData Receiver Adapter is as follows:
And, this is the configuration of
JMS Receiver Adapter:
Property |
Value |
Queue Name |
Products |
The
JMS Receiver Adapter creates the queue if it does not already exist and puts the message into the queue. In the context of this blog, a JMS Queue acts as a Message Channel.
Once the flow runs, we can see the message in the channel in monitoring.
A message in the Channel
Integration Flow - Consume from a Channel
Consume from a Channel
The consumption of the message from a channel is achieved using the
JMS Sender Adapter. In this flow,
JMS Sender Adapter consumes the message in the specified channel and the Log script logs the message for monitoring.
The configuration of
JMS Sender Adapter is the same as that of
JMS Receiver Adapter:
Property |
Value |
Queue Name |
Products |
The Log
Groovy Script code is as follows:
import com.sap.gateway.ip.core.customdev.util.Message
def Message processData(Message message) {
def messageLog = messageLogFactory.getMessageLog(message)
messageLog.addAttachmentAsString('Body', message.getBody(String), null)
return message
}
When the integration flow is deployed the message is consumed and logged in monitoring:
Output
EIPinCPI Rating - 10/10
As CPI has extensive support of JMS, the Message Channel pattern is fully supported in CPI. Therefore, the rating of 10/10 is justified.
Conclusion
Message Channels are a way of organising data flowing through the middleware. Sender(s) will put the message into a channel and Receiver(s) will consume the messages in a given channel.
References/Further Readings
Hope this helps,
Bala
Previous – Service Activator | Index | Next – Point-to-Point Channel