Skip to Content
Technical Articles
Author's profile photo Bhalchandra Wadekar

EIPinCPI – Message

Previous – Index | Index | Next – Command Message

This week, we’re going to study our first integration pattern known as Message.

When do I use this pattern?

I like to think of Integration as ‘enablement of two systems to talk to each other’. How can two systems talk to each other? By exchanging messages. Therefore, Message pattern is always used.

Message in Apache Camel

CPI uses Apache Camel underneath. So, it makes sense to understand the implementation of Message pattern in Apache Camel first. In Apache Camel, interface Message is used to implement Message Pattern.

Note: This class diagram only contains the methods pertaining to headers and the body. For a complete picture of this class, check the Javadoc for Message in Apache Camel.

From the class diagram, we understand that Message is made up of Headers and a Body. The main content of the message will be held in Body. Complimentary information is stored in Headers. For example, if customer information needs to be shared with a target system, Customer Information will be stored in the body whereas headers can contain information about authentication for the target system.

Note that headers are name-value pairs where name is String and value is Object. In Java, Object is the parent class of all classes by default. This enables the Apache Camel Message to have any kind of headers. Examples of different types of headers include

  • a String such as ‘authorization’ header, ‘content-type’ header, and so on,
  • a Map such as ‘set-cookie’ header

Furthermore, the type of body is also Object and therefore the body can be a file, a SOAP message, a JSON response, and so on. This enables Apache Camel to be payload-agnostic.

Complete source code for Message interface is available in Github repository ‘apache/camel’.

Message in CPI

In CPI, a similar interface is available – com.sap.gateway.ip.core.customdev.util.Message. For all the methods in this interface, check the Javadoc for Message in CPI.

The notable difference between Apache Camel Message and CPI Message is the addition of properties. Properties are name-value pairs where name is String and value is an Object. Properties can be used to store information for later use. For example, if the target system uses OData then the value of primary keys from the source message can be stored in properties for use in the URL for updating the target entity.

But where do properties come from?

Where were the properties hidden in Apache Camel’s Message? Properties belong to Exchange class. Exchange is a container around Message during Routing. In CPI, the methods for properties are basically invoked on Exchange.

For example, getProperty()‘s implementation is something like:

Object getProperty(String name) {
    this.getExchange().getProperty(name)
}

I’ll leave the explanation of Exchange to another blog.

If you are interested in learning about not only Exchange but also Message, watch the first 9 minutes and 50 seconds of Week 1 Unit 5 video of openSAP Course for SAP Cloud Platform Integration.

Conclusion

Two systems that need integration talk to each other by exchanging messages. Message pattern is always used.

References/Further Readings

Hope this helps,
Bala

Previous – Index | Index | Next – Command Message

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.