Skip to Content
Technical Articles

EIPinCPI – Service Activator

Previous – Idempotent Receiver | Index | Next – Message Channel

This week, we’ll learn one of the most common patterns known as Service Activator.

When do I use this pattern?

Service Activator acts as a translator between the service exposed by the Message Endpoint and the messaging system. For example, an OData service can be consumed in CPI using a Service Activator commonly known to us developers as OData Receiver Adapter.

Service Activator in CPI

In CPI, I’ll demonstrate the OData Receiver Adapter as a Service Activator.

Integration Flow

OData%20Service

OData Service

The integration flow starts immediately using Timer Start Event, gets the product from Northwind OData Service using OData Receiver Adapter, and Logs the message contents using a Groovy Script.

The Service Activator is implemented as OData Receiver Adapter. The OData Receiver Adapter invokes the OData service using HTTPS, the HTTP response body is converted to a nicer format and stored into the message body. whereas headers are copied into message headers. A CamelHttpResponseCode header is also set.

The Log Groovy Script shows us the content of the Message. The script is like so:

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
    
    def messageLog = messageLogFactory.getMessageLog(message)

    messageLog.addAttachmentAsString('Headers', message.headers.collect { key, value ->
        key + ':\t' + value
    }.join('\n'), null)
    messageLog.addAttachmentAsString('Body', message.getBody(String), null)

    return message
}

Output

Headers

CamelHttpResponseCode: 200
HttpStatusCodes: OK
ODataResponseType: Properties
SAP_MessageProcessingLogID: AF-DILhznrDxdh_O8s9gq-HkSMD8
SAP_MplCorrelationId: AF-DILgcLpXDWMgi0y190B6yKRrJ
SAP_PregeneratedMplId: AF-DILhK89mz6lm-NFvqmuw9SM3M
scriptFile: script1.groovy
scriptFileType: groovy

Body

<Products>
    <Product>
        <CategoryID>1</CategoryID>
        <Discontinued>false</Discontinued>
        <SupplierID>1</SupplierID>
        <UnitPrice>18.0000</UnitPrice>
        <ProductName>Chai</ProductName>
        <QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit>
        <UnitsOnOrder>0</UnitsOnOrder>
        <ProductID>1</ProductID>
        <ReorderLevel>10</ReorderLevel>
        <UnitsInStock>39</UnitsInStock>
    </Product>
</Products>

As you can see the raw HTTP response from OData service was nicely wrapped in a Message by the Service Activator.

EIPinCPI Rating – 10/10

CPI has a number of out-of-the-box Service Activators, called as Adapters for most common protocols and applications. A developer can also develop adapters if required. In addition, the Cloud Platform Integration Suite has Open Connectors that allow connection to many applications. Therefore, CPI has a full rating of 10/10 for the Service Activator pattern.

Conclusion

Service Activator pattern enables us to consume and provide services from the messaging system without the consumer/producer having knowledge of the messaging code.

References/Further Readings

Hope this helps,
Bala

Previous – Idempotent Receiver | Index | Next – Message Channel

/
OData%20Service
1 Comment
You must be Logged on to comment or reply to a post.
  • Can we configure the more data receiver adapter while activating? what’s the minimum or max   quantity we can configure here.

     

    Thanks in advance .

    Kaerin G. Redd