MVC, where do I invoke my messaging integration layer from?


Model View Controller (MVC), is an architectural pattern and is defined as:

“It is common to split an application into separate layers that run on different computers: presentation (UI), domain logic, and data access. In MVC the presentation layer is further separated into view and controller.

MVC is often seen in web applications, where the view is the actual HTML page, and the controller is the code that gathers dynamic data and generates the content within the HTML. Finally, the model is represented by the actual content, usually stored in a database or in XML nodes, and the business rules that transform that content based on user actions.” Courtesy: Wikipedia (including the image below).

MVC

Note that the MVC pattern does not provide guidance on where the integration code should be (for example when connecting to a MQ system) and which layer in MVC should invoke it?

What is messaging system integration layer or gateway pattern?

In the world of integrating applications (also called EAI) using messaging, the purpose of a messaging system integration layer or gateway pattern is to decouple the application from the destination message queuing system. For example assume if the web application architecture is implemented following a layered pattern in combination to MVC, then the messaging system integration layer or gateway pattern code would be responsible for four things:

a) Establishing connection to the destination message queuing system

b) Handling data format (marshaling or un-marshaling to and from XML data format)

c) Exception handling

d) Sometimes failover (applicable only when this is implemented in the code).

The problem and the solution:

While the gateway pattern or integration layer abstracts the code required to connect to messaging infrastructure, however, which layer in MVC should invoke this pattern? Obviously this determines how loosely the application would be coupled to the messaging layer/infrastructure. The design heuristics to solve this problem is largely influenced by the application architecture. From my experience, the greater the abstraction of the messaging layer from the application and invoking it from an application’s domain layer or domain model pays off pretty well. What are your thoughts? Share them in the comments below.