BizTalk's loose-coupling: message views

Service Station, by Aaron Skonnard

Syndication

One of the things that really turns me on about BizTalk is how it truly enables loose-coupling via XML messaging. Like I said in this post, loose-coupling is a term that is often flung around but rarely achieved in practice especially by most of today's Web services frameworks, which is ironic. Achieving loose-coupling throughout a system is typically accomplished by exchanging messages that both sides understand. However, the key to loose-coupling is enabling flexibility in the local interpretation of the contract.
 
When System A sends an invoice message to System B, and System B is able to process it successfully, one could argue that it's loosely-coupled. However, the local processing code running on System B is often tightly-coupled to the message contract, disallowing possible deviations. In this case, if the message coming isn't valid according to the message contract, the system rejects the message and fails. This is an example of local code that is tightly-coupled against the message contract. A loosely-coupled implementation would simply look for the elements and attributes that it needs to function properly and ignore the rest.
 
This is how most successful - and widespread - XML applications work today. RSS is a great example. There are numerous competing RSS-like formats and differing implementations. And on top of that, there are many invalid RSS feeds floating around the Web that we successfully consume. This is because RSS applications can be built in a way to look for the elements it absolutely needs to function and handle missing stuff gracefully. The key here is the flexibility in the local processing logic relative to the RSS formats.
 
What's interesting today is that most Web services frameworks generate services that are tightly-coupled to their message contracts. I find this interesting because despite that fact, they usually don't provide built-in validation mechanisms. XmlSerializer tries to be loose, but doesn't quite make it, plus the mapping to objects confuses the issue and drops XML's flexibility on the floor. Since the code on each side of the wire tends to be tightly-coupled, many of us argue that in order to ensure interoperability, one should start by defining the message contract and then generate the implementation code for each side (contract-first). This typically ensures that both sides with produce/consume the same message formats.
 
BizTalk is different. It BizTalk provides out-of-the-box mechanisms for supporting numerous message formats that essentially convey the same information. For example, a given BizTalk business process (orchestration) can be defined in terms of a single XML message format (think of it as the "internal view") and then you can define multiple entry points (ports) for invoking that business process, each of which expects a different message format (an "external view"), which may be communicated over different transport protocols. You can also define automatic transformations the will occur between the external/internal views when passing through a port. This is your chance to look for the pieces of information you care about - that you absolutely need to function properly - and map it accordingly, ignoring possible deviations. These transformations are most often between differing XML formats, but they can also handle non-XML formats as well.
 
BizTalk takes things even further. In order to inspect messages as they travel through BizTalk, you must "promote" fields and properties on the message that BizTalk will make available to you. I like thinking of this as another view of the message, similar to a database view. You define what parts of the message are needed within the business process (via promotions), then BizTalk takes care of making those available to you, while ignoring the other information found in the message as it travels through the system. This offers some powerful possibilities in the light of this discussion on loose-coupling.
 
At the recent Indigo SDR, I had some interesting discussions with various folks on the possibilities of adding a similar feature to Web services stacks. Can you imagine a model where you author Web service signatures by mapping method parameters to XPath expressions that will be evaluated against incoming messages? The mapped parameters would be equivalent to BizTalk's notion of promoted properties. This ability would give Web service developers greater flexibility in building loosely-coupled endpoints capable of dealing with a variety of message variants. Obviously it would not be the right fit for every application, but it would give WS developers the IDispatch equivalent in a message-oriented world.
 
Obviously, the implications of such a model would greatly impact the way I feel about contract-first development.
 

Posted Apr 15 2005, 01:04 PM by Aaron Skonnard
Filed under: , ,

Comments

Bill de hOra wrote re: BizTalk's loose-coupling: message views
on 04-15-2005 4:01 PM
Ah. This depends on the contract! Property lifting works when the contract has been overspecified or when the data just ends up on the screen anyway (for example your argument can be applied to typing exceptions - who cares what the type is, when we're just going to log and notify anyway?).

Granted it's common to see demands that everything 'be there' just in case. But I wonder how BizTalk itself would function under such looseness, ie messages from time to time arriving with no eps:from element. It really depends on what the data is targeting.

It's excellent that you can mine for loose coupling and exploit it in BizTalk, but I think this speaks to the process of defining contracts in enterprise situations as much as anything else. And the amount of loose coupling you can push for seems to be a function of how much machinery the process entails. Formats like HTML and RSS are hugely robust because people are available to fill in the blanks. WS formats that leverage xsd types are less so. And there's stuff like RDF which is designed from the ground up to allow machines to function gracefully on receiving partial content.

The XPath idea I've seen used for allowing documents that have similiar semantic items but have variant structures to be processed uniformly. You associate a document (via namespace oe mimetype) with a set of XPaths that map onto the semantic abstractions, which in turn end up as arguments to a function or keys in a map. It's a good trick for dealing with document versions where backward compatibility is an issue. It's an idea with a history; SGML folks would probably call this architectural forms. Dynamic folks would call it duck typing. Another approach that achieves the same end is to transform the varying documents to a canonical form before handing off to handler for processing.

Personally, I use the idea of schema 'traps' as determing architectural and trust boundaries: http://www.dehora.net/journal/2005/03/trust_and_robust.html. Understanding the boundaries are important for building robust decentralized systems and figuring where the boxes and arrows really are in an architecture (usually not where you thought they were!).
Stefan Tilkov's Random Stuff wrote links for 2005-04-28
on 04-28-2005 2:21 PM
BizTalk’s loose-coupling: message views BizTalk is better than many people think (tags: webservices) Contract-First Service Development Part I (tags: webservices) XQEngine, an open-source, XQuery-based, embedded Java component for querying XML documents. (tags: xml) We do stuff. The funniest thing is the Google ads which blend right in with the rest (tags: fun) Chris Coyne.com CFDG - Context Free Design...

Add a Comment

(required)  
(optional)
(required)  
Remember Me?