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

EIPinCPI – Detour

Previous – Control Bus | Index | Next – Wire Tap

This week, we’ll study the next system management pattern known as Detour.

When do I use this pattern?

Detour is simply a router for debugging. For example, it is common in CPI to write a Groovy Script for logging, however, the logging is only done based on a configurable parameter. In CPI, the logging can also be controlled by switching the Log Level (None for disabling logs and Other Log Levels for enabling logs).

There is a difference between a standard router and a Detour. A standard router often affects the destination of the message. Whereas, Detour routes the message to perform extra steps that do not affect the destination of the message. For example, the message is passed as it is to the next step whether it is logged or not. Another example is validations built to help during development or testing phase. In the production environment, where all the input messages are expected to be valid, the validations may be turned off in favour of performance.

Detour in CPI

For the demonstration, I’ll implement the Detour for logging in CPI.

Integration Flow

Log

Log

The integration flow starts immediately using a Timer Start Event. Next, using a Content Modifier sets the body and an exchange property ‘Log’ to toggle logging. Finally, using Router checks if Logs are enabled. If logs are enabled, a Groovy Script logs the body, otherwise, the flow ends.

Configuration of Set Body Content Modifier

In the Properties tab, we create a property Log to control the logging. This is set to a configurable parameter ‘Log?’ so that it can be controlled through the Control Bus, i.e., the Configure option in the Design tab.

Action Name Type Data Type Value
Create Log Constant {{Log?}}

Configuration of Log? Router

The ‘Log?’ Router routes based on the property ‘Log’ set in the previous step.

Order Route Name Condition Expression Default Route
1 Yes ${property.Log} = ‘Yes’ Unchecked
2 No Checked

Log Groovy Script

This is perhaps the most used script in the CPI world.

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
}

Example Run – Using Control Bus from the Design Tab

First I use the Control Bus from the Design tab, i.e., I will configure the parameter ‘Log?’ to ‘Yes’ and ‘No’.

Log? = ‘Yes’ – Input

Input

Log? = ‘Yes’ – Output

When the flow is deployed, the body is attached to the message log.

Output

Log? = ‘No’ – Input

Input

Log? = ‘No’ – Output

When the flow is deployed, the message log does not show attachments

Output

Output

Example Run – Using Control Bus from the Monitor Tab

The integration flow logging can also be controlled through the Monitor Tab by setting the Log Level.

Log Level = ‘Trace’ – Input

Log Level = ‘Trace’ – Output

At Log Level ‘Trace’, a link is shown under the Logs tab in Monitoring.

Clicking on the Trace link opens a new view wherein the developer can view the Integration Flow Model, Log Content, and Message Content at each step. For example, the screenshot below shows the Message Body set in Set Body step.

Log Level = ‘None’ – Input

Log Level = ‘None’ – Output

Setting the Log Level to ‘None’ results in no logs at all.

In a Nutshell

Please note that logging is one example where Detour pattern can be applied. And, as demonstrated above, in CPI, logging is controlled better using Log Level rather than a custom Detour pattern. Using Log Level is better as it doesn’t require redeployment of the flow (except where the message is generated on Redeployment, for example, Timer Start Event is used with Run Once schedule) and it doesn’t require custom code enabling the integration code to be focussed on business requirements rather than technical requirements.

However, Detour pattern can be used to enable/disable validations, for example, during initial load.

EIPinCPI Rating – 10/10

With the solid implementation of Message Router pattern and support for Configurable Parameters, CPI supports the Detour pattern completely. Hence, a rating of 10 out of 10.

Conclusion

Detour pattern is an excellent way to write code that can be toggled from Control Bus.

References/Further Readings

Hope this helps,
Bala

Previous – Control Bus | Index | Next – Wire Tap

Assigned Tags

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