This week, we study another variation of Message pattern known as Document Message.
When do I use this pattern?
A Command Message invokes functionality in the target system, whereas, a Document Message is just a message sent to the target system. A Document Message does not tell the receiver system what to do with the message. Examples of the Document Message pattern include a response message from an invoked SOAP operation and sending an Email.
Document Message in CPI
A response message from an invoked SOAP operation
Last week, I commanded W3 Schools to convert 37 ℉ to Celsius. The full response message from W3Schools is:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <FahrenheitToCelsiusResponse xmlns="https://www.w3schools.com/xml/"> <FahrenheitToCelsiusResult>2.77777777777778</FahrenheitToCelsiusResult> </FahrenheitToCelsiusResponse> </soap:Body> </soap:Envelope>
Here, the content between Body element is a document message returned to CPI without telling CPI what to do with it. CPI chose to log that response for monitoring.
Sending an Email
Another example of Document Message is sending an Email. When an email is sent, the email server is free to choose the future of the received message. Some examples of future actions taken by the email server are to assign a tag to the email, move the email to the junk folder, add a line at the top to say “This Email is from External Network. Be careful when clicking on links.”, and so on.
This is a simple integration flow. It starts as soon as it is deployed and sends the email document.
Here are the configurations I used:
|Connection||Credential Name||Gmail Credentials|
|Connection||From||My Email Address|
|Connection||To||My Email Address|
|Connection||Mail Body||Hello, World!|
When integration flow is deployed, I receive the email in my Google Account.
The code is available as Integration Recipe on SAP’s official repository: EIP-MessageConstruction-DocumentMessage
- Document Message Pattern in Enterprise Integration Patterns
- Gmail Connectivity from CPI
- CPI Components
Hope this helps,