Click here to Skip to main content
15,881,588 members
Articles / Programming Languages / C#
Article

Message & InfoBus Components

Rate me:
Please Sign up or sign in to vote.
3.67/5 (12 votes)
9 Dec 20023 min read 56.1K   1K   27   5
An article on message/info bus components for lightweight messaging.

Sample Image - message_infobus.gif

Introduction

This is a group of components that can easily be added to any application needed some kind of lightweight messaging framework.  Much simpler than the MessageQueue class, these components themselves are completely integratable with Visual Studio.NET, as you can see from the above image of the test client using the SingletonMessageBus component. NOTE: this project is dependent on NUnit to build (see the nunit site) but hey, we all unit test, so you've already got this installed, right? :)

Background

I was developing a rich client that needed to consume a web service.  This was an MDI based application, for the most part in which I was using a model-view-controller (MVC) design in the window implementations.  I noticed, however, that when you had a situation with multiple potential models, the MVC paradigm became somewhat burdensome.

To solve this problem, I created the two messaging systems included in this DLL.  In most cases, unless you find yourself in a situation where you need multiple busses of the same type in your application, the SingletonMessageBus and SingletonBuilder give you an easy and fast way to implement this kind of messaging.

I wanted to avoid using the MessageQueue class because it was just too heavyweight for what I needed.

Using the code

The controls are pretty straightforward to use.  Just build the project, and add the resulting DLL to the toolbox, and the components should appear as shown in the first image in this article.

The SingletonMessageBus is very easy to use as it supports a single event, really, only a single method of interest.  For example, the above image shows a child form from the test project which aggregates a SingletonMessageBus component.  Double-clicking on the component will create a handler for the default event, which would look something like this:

C#
private void singletonMessageBus1_Message(object sender,
    OsoGrande.Notification.Message.MessageEventArgs e)
{
    // You can catch your own messages if needed, as well as messages
    // from others.
    if ( sender == this )
        MessageBox.Show( "Caught my message." );
}

The handler, of course, is automatically added to the Message event by the Visual Studio.NET IDE:

C#
// 
// singletonMessageBus1
// 
this.singletonMessageBus1.Message += 
    new OsoGrande.Notification.Message.MessageHandler(this.singletonMessageBus1_Message);

Submitting messages is equally easy via the SubmitMessage() method:

C#
this.singletonMessageBus1.SubmitMessage( this, 
    new MessageEventArgs(null, this.isEnabled ) );

That's it! The message is delivered to all registered listeners.  The InfoBus component is more complex in that the protocol is a bit more convoluted, but it acts in roughly the same way.  Specifically, the InfoBus itself is aggregated into the Builder, which adds and removes data consumers and producers from the bus. Consumers are notified of the existence of data, indicate interest (if any), are delivered the data, and can then choose to opt out of future notifications from that specific producer if deemed appropriate.

The components are fully integrated and the classes implementing these components are contained in a separate support DLL and aggregated via the Bridge pattern to the classes implementing any component-specific features.

Points of Interest

This was a good exercise in component development, in that in the InfoBus communication that traditionally was modeled as method calls I converted to events to support higher ease of integration with Visual Studio.NET.

Update History

  • 12/03/2002 - Initial Submission
  • 12/10/2002 - documented a dependancy

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWaste of time Pin
sytelus28-Jan-03 18:01
sytelus28-Jan-03 18:01 
GeneralRe: Waste of time Pin
Anonymous20-May-04 15:48
Anonymous20-May-04 15:48 
GeneralNUnit Dependency Infomation Pin
lambo826695-Dec-02 5:42
lambo826695-Dec-02 5:42 
QuestionMissing? Pin
Rocky Moore5-Dec-02 0:28
Rocky Moore5-Dec-02 0:28 
GeneralThis looks to be very useful Pin
Marc Clifton4-Dec-02 11:17
mvaMarc Clifton4-Dec-02 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.