Skip to Content
Technical Articles

EIPinCPI – Message Bus

Previous – Messaging Bridge | Index | Next – Control Bus

This week, we’ll study a pattern known as Message Bus.

When do I use this pattern?

Message Bus is useful where multiple applications providing similar functionality are involved. For example, in a merger of businesses, the two companies may use different software for holding products information. A message bus will receive product request data and pass it to the appropriate system. Choosing the appropriate system requires the use of a Message Router. Whereas, sending the product request to the chosen system can be done through Command Message. If the end system does not understand messaging, then a Channel Adapter could be used. Message Bus is this combined effort of different patterns to expose one common interface while keeping the participating systems lowly coupled to each other such that any system could be added/removed easily with future mergers/liquidations.

Message Bus in CPI

In the example, I will connect to Northwind system and SAP ES5 system to expose the products API.

Integration Flow

Fetch Product Information

This integration flow exposes the API using HTTPS Sender Adapter. The configuration of the HTTPS Sender Adapter is as follows:

Tab Property Value
Connection Address /Products
Connection CSRF Protected Unchecked

The Content Modifier is used to move the header value of ProductName into an exchange property.

The first Content Enricher connects to Northwind Service using OData Receiver Adapter and fetches product information. The configuration of this OData Receiver Adapter is as follows:

Tab Property Value
Connection Address https://services.odata.org/V2/Northwind/Northwind.svc
Connection CSRF Protected Unchecked
Processing
Operation Details Query (GET)
Processing
Resource Path Products
Processing
Query Options $filter=ProductName eq ${property.ProductName}

The second Content Enricher connects to SAP ES5 server using OData Receiver Adapter and fetches product information. The configuration of this OData Receiver Adapter is as follows:

Tab Property Value
Connection Address https://sapes5.sapdevcenter.com/sap/opu/odata/sap/EPM_REF_APPS_PROD_MAN_SRV
Connection Authentication Basic
Connection Credential Name ES5 Credentials
Connection CSRF Protected Unchecked
Processing
Operation Details Query (GET)
Processing
Resource Path Products
Processing
Query Options $filter=Name eq ‘${property.ProductName}’

Both Content Enrichers are configured to combine the message as it is.

A Message Translator can be added after all Content Enrichers to convert the response into a Canonical Data Model.

Execution

When the API is invoked, the ProductName is received in the HTTP headers. Content Modifier moves the header into the property. Then, the flow invokes each system in sequence and whichever system has the product populates the output message body.

Output from Northwind

For example, when invoked with the header ProductName as Chai, the product is fetched from Northwind system and the output is like so:

<?xml version='1.0' encoding='UTF-8'?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <multimap:Message1>
        <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>
    </multimap:Message1>
    <multimap:Message2>
        <Products/>
    </multimap:Message2>
</multimap:Messages>

Output from ES5

When the Name from ES5 is sent in the header ProductName, the product is fetched from ES5 like so:

<?xml version='1.0' encoding='UTF-8'?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <multimap:Message1>
        <Products/>
    </multimap:Message1>
    <multimap:Message2>
        <Products>
            <Product>
                <Description>Notebook Basic 15 with 2,80 GHz quad core, 15" LCD, 4 GB DDR3 RAM, 500 GB Hard Disc, Windows 8 Pro</Description>
                <MainCategoryId>Computer Systems</MainCategoryId>
                <StockQuantity>149</StockQuantity>
                <SubCategoryId>Notebooks</SubCategoryId>
                <ImageUrl>/sap/public/bc/NWDEMO_MODEL/IMAGES/HT-1000.jpg</ImageUrl>
                <WeightUnit>kg</WeightUnit>
                <DimensionUnit>cm</DimensionUnit>
                <DimensionHeight>3</DimensionHeight>
                <Name>Notebook Basic 15</Name>
                <CurrencyCode>USD</CurrencyCode>
                <SubCategoryName>Notebooks</SubCategoryName>
                <LastModified>2020-12-27T03:01:02.000</LastModified>
                <SupplierId>100000000</SupplierId>
                <DimensionWidth>30</DimensionWidth>
                <MeasureUnit>each</MeasureUnit>
                <WeightMeasure>4.2</WeightMeasure>
                <MainCategoryName>Computer Systems</MainCategoryName>
                <SupplierName>SAP</SupplierName>
                <Price>956.00</Price>
                <RatingCount>3</RatingCount>
                <AverageRating>3.67</AverageRating>
                <Id>HT-1000</Id>
                <DimensionDepth>18</DimensionDepth>
                <QuantityUnit>EA</QuantityUnit>
            </Product>
        </Products>
    </multimap:Message2>
</multimap:Messages>

EIPinCPI Rating – 10/10

With the solid support of component patterns, Message Bus pattern gets full 10 out of 10.

Conclusion

Message Bus pattern is a combination of other patterns that enables connecting multiple systems providing a similar system in a low coupled way.

References/Further Readings

Hope this helps,
Bala

Previous – Messaging Bridge | Index | Next – Control Bus

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