Skip to Content
Technical Articles

EIPinCPI – Message History

Previous – Wire Tap | Index | Next – Message Store

This week, we’ll explore another system management pattern known as Message History.

When do I use this pattern?

Message History is useful to analyse the error. The message history contains the list of components that the message has been through and the component that caused the error.

Message History in CPI

Accessing Message History using Apache Camel

As CPI uses Apache Camel, the message history is available as List of MessageHistory object in the Exchange.MESSAGE_HISTORY property on the Exchange.

The history can be accessed in the groovy script by simply reading the property on the message. In the code below, messageHistories variable will have the List of MessageHistory object. Later, all the message histories have simply been logged.

import com.sap.gateway.ip.core.customdev.util.Message
import org.apache.camel.Exchange

def Message processData(Message message) {

    def messageHistories = message.getProperty(Exchange.MESSAGE_HISTORY)

    def messageLog = messageLogFactory.getMessageLog(message)
    messageLog.addAttachmentAsString('Message History', messageHistories.join('\n'), null)

    return message
}

The sample output of the above script looks like this:

 

Sample%20Output

Sample Output

Here, the route Id ‘Process_1’ can be seen in the flow by clicking on the Integration Process and then clicking on the Technical Information button. And, similarly, we can find out node Id in the technical information of individual nodes, for example, the Log History Groovy Script node has Id ‘CallActivity_6’ or the line number 3 in the sample output above.

How%20to%20find%20the%20Id

How to find the Id

As you can see, the message history is available through APIs using Apache Camel, but the Ids are determined by CPI and can’t be set by us developers. However, not being able to set the Ids is trumped by the UI of Message History.

Accessing Message History through UI

The best part of CPI is that while the API is available to dig deep, the Message History can also be viewed visually in Monitoring.

For example, let’s run the example from Content-based Router pattern.

In this run, the message was received by HTTPS Sender Adapter. Then the Country? Router chose the UK Branch based on the condition. Eventually, the message failed at the HTTP Receiver Adapter. And, all this information is available to the developer through Monitoring UI.

Failure

Failure

The developer can then select an individual step, either in the list view on the left or in the Integration Flow Model itsef. For example, clicking on HTTP step and then on Log Content shows the error.

Failure

Failure

Note that all these helpful debugging information is available at Info Log Level. In the Debug or Trace level, Message Content is also available. Whereas, in the None Log Level, no logs are available, including message history.

EIPinCPI Rating – 10/10

With the access to Message History through an excellent UI and also through APIs, the Message History pattern is implemented greatly giving great debugging capabilities to the CPI developer. Therefore, a full rating of 10 out of 10 is justified.

Conclusion

Message History is useful for root cause analysis. And, CPI has great implementation to access Message History both at the runtime using Java/Apache Camel API and after the message has been processed through UI.

References/Further Readings

Hope this helps,
Bala

Previous – Wire Tap | Index | Next – Message Store

2 Comments
You must be Logged on to comment or reply to a post.