Sunday, May 19, 2013

Publish Subscriber Pattern in ArchiMate

On the ArchiMate forum on LinkedIn, Stéphane Passignat posed the following question: 


There are a number of aspects here:
1) ("using ESB topic") How do you model a Topic with associated data?
2) ("from an application component to another application component") How do you show the application using the topic?
3) ("any kind of pub sub pattern") How do you model generic Publisher and Subscriber patterns with associated data?

What is the Publisher Subscriber Pattern? 

This pattern is for an event to be broadcasted to multiple listeners. The same event may be broadcast by multiple originators. This is an Event-Driven Messaging pattern in SOA and a Publish-Subscribe Channel in Enterprise Intergration Patterns (EIP).

Enterprise Integration Patterns describes the problem as "How can the sender broadcast an event to all interested receivers?" The solution is a topic with one or more publishers and multiple subscribers.

Figure 1 - EIP Publish-Subscribe Pattern
Figure 1 - EIP Publish-Subscribe Pattern


Here it is very clear that a single message is delivered through a "channel" to multiple subscribers. I have created a very simple context for reference, however this time using the SOA template form Thomas Erl.

Figure 2 - Onboarding Scenario for context in the discussion
Figure 2 - Onboarding Scenario for context in the discussion

Here as part of an on boarding process an employee is added to a HR system. The service that configures the new employee broadcasts via a New Employee Event Service provided by ActiveMQ that the new employee exists. This message is picked up by the Create Account Service and an account is created into LDAP. I was also going to add the Training Enrollment Service as the second subscriber but one is enough to show the principle.

A Note on Syntax for ArchiMate

I am using the labeling syntax from Mastering Archimate Edition 1. It helps to identify what some of the objects are associated from other layers when not in a total view or using a tool like Archi which provides a visualization between layers while editing a particular view. It also helps in the menu to quickly grab the right object:

Figure 3 - Snapshot of Application elements from Archi
Figure 3 - Snapshot of Application elements from Archi


How do you model a Topic with associated data? 

The first one in ArchiMate can be done through a technology layer, describing how the infrastructure  provides a topic as an Infrastructure Service, an Infrastructure Interface and associated Artifacts.  Here in Figure 1, I have modeled an example of Fuse Message Broker(FMB) as the MOM layer for the ESB. FMB is an ActiveMQ implementation and for distinction I have named it as an ActiveMQ infrastructure.


Figure 4 - MOM Infrastructure with service, interface and artifact
Figure 4 - MOM Infrastructure with service, interface and artifact

Described is a virtual server with RedHat Linux, and ActiveMQ as a System Software. The underlying systems are all aggregated as ActiveMQ Node. The Node realises a the infrastructure service "New Employee Topic". The topic accesses a "New Employee Message" which is an artifact on the system. This could be stored as a file or in an RDBMs depending on the setup but for this I have not dived that deeply. The Node also presents and external Infrastructure Interface to the Topic. 

So how do you show the application using the topic?

Here I have taken the liberty of not modeling the infrastructure of FuseSourceESB. Instead I am modeling the services ('applications') deployed onto the ESB and how they access the infrastructure of ActiveMQ. I have done it through a Used-By relationship. There is a problem with this view. It does not show who is the publisher and who is the subscriber only which are using which. If there was only one publisher and multiple subscribers the Used-By relationship still would not identify the specific roles. In the Infrastructure with Usage view in ArchiMate there is no way of showing the flow.

Figure 5 - Infrastructure with Usage view of 2 service Components using the ActiveMQ New Employee Topic
Figure 5 - Infrastructure with Usage view of 2 service Components using the ActiveMQ New Employee Topic


Here we are at component level and we can see that the Employee data object is part of the New Employee Message data object via the composed of relationship.  In this view the Employee data object is accessed by the Configure New Employee but I have not shown the fact that the Create Account component would also access it once it had extracted it from the New Employee Message. I would but I want to highlight where it originates from this this case.

The infrastructure artifact is now shown as the realisation of that New Employee Message data object. It is accessed by the New Employee Topic infrastructure service to which the New Employee Topic Interface is assigned.  

How do you model generic Publisher and Subscriber patterns with associated data? 

The answer that I propose to the problem is Application Interaction using an Application Co-Operation View.


Figure 6 - Application Co-Operation view using an Application Interaction to describe a New Employee Event
Figure 6 - Application Co-Operation view using an Application Interaction to describe a New Employee Event

Here we can see the Application Interaction showing the flow of the message from the one to application to another. The "Configure New Employee" function initiates the "Broadcast New Employee Event" function which flows to the "New Employee Event" interaction.

This Application Interaction shows a 3 way interaction pattern between the publisher the channel and the subscriber as per the Publish-Subscribe Channel pattern. You can easily add more subscribers to the flow though with ArchiMate you may find allot of overlap between lines so I would recommend a second view with all the subscribers and no data object once there is one view with a data object.

I hope this helps and feel free to suggest improvements and alternatives.