Messaging Pattern

last modified: March 27, 2010

The below has been copied from http://freedom.lunarpages.com/pattern/messaging.htm (Of course. we are same authors !?>

Really? Then perhaps it makes sense to link to it, rather than include the content here? And why are you deleting the criticism and links to related pages?

Yes. It is a fact. Criticism is fine. Obviously it needs to be based on facts. Please send it to jtowner@dev.java.net or the design pattern mailing lists. We'll be happy to address it.

This is a public forum. If you're going to post some of your pattern here, it seems appropriate to address the criticism here. Therefore, I am going to re-include it below. Feel free to respond here, but merely deleting the criticism is inappropriate.

I'm afraid your information is not factual. "Write only factual information". I'm moving in it for now because it is misleading. For now I'm moving it until we get the time to address it.

If you feel it is inaccurate, please at least identify what you believe to be the inaccuracies. I'm sure the author of the criticism (which is not me) will be happy to comment, clarify and expand. However, I am inclined to agree with the weaknesses that were identified, so I am moving the criticism back along with the related links. By the way, your "Motivations (forces)" section doesn't actually identify any motivations or forces, and because the images found on your Web page aren't included, you've got headings (e.g., "Messaging Design Pattern (without messenger involved)") without associated content.

Related: MessagePassing, MessageDefinition, ComponentBus

Known Weaknesses (since none are listed below):


Messaging Design Pattern

Intent: The messaging design pattern allows the interchange of information (i.e. messages) between components and applications.

Motivations (forces): This design pattern can be applied to solve a great variety of problems in many diverse scenarios. A messaging paradigm is widely used in the real world. Messages are interchanged all around us. Entities are constantly sending, receiving and processing messages. Human beings for instance: when we watch TV, when we talk to a friend, talk over the phone, or send an email message. Right now, you are reading this written message. Since computer applications seek to model the real world, it is only natural to design and write applications using a messaging approach. We can argue that messaging provides a better and more accurate representation (i.e. model) of the real world. As a consequence, software engineering processes are significantly improved by the use of the messaging design pattern.

Participants:

a) Message Sender: Component that sends the message. b) Message Recipient (Receiver): Component that receives the input message and produces a reply (output message) after processing it. The input message, general in nature, may contain any type of information. The component may be instructed to perform computations based on the input message. c) Messenger: Intermediary that transfers the message from the sender to the recipient. The sender and the recipient don’t need to be concerned about how the message is transferred (communication protocol, message format, encryption/security mechanism, etc.) and the transformations performed on the message along the way. This is the messenger’s purpose and responsibility. Similar to the real world, it is often the case that the messenger is not required. The message can be sent directly to the message recipient. d) Message: any piece of information (i.e. data) that needs to be interchanged between sender and recipient. Two messages are involved: input message and output message (or reply message).

Structure:

The messaging design pattern is implemented using the messaging interface (JtInterface). This interface consists of a single method to process the input message and produce a reply message.

Messaging Interface

Messaging Design Pattern

Messaging Design Pattern (without messenger involved)

Consequences:

Known uses:

Implementation and Code Examples:

The messaging design pattern is implemented using the Jt messaging interface (JtInterface). This interface consists of a single method:

public interface JtInterface {

/**

* Jt messaging interface used for the implementation
* of the messaging design pattern.
* Process an input message and return a reply (output message). 
*/

Object processMessage (Object message); 

},

The JtInterface is simple but powerful. The simplicity of this interface can be deceiving. One method is all that is needed. It acts as a universal messaging interface that applies to remote and local framework components. This interface handles any type of message (Object class).

The following example sends a message to a remote component/Restful service via a remote proxy. The messaging design pattern is able to handle any communication protocol/technology (Web Service, EJBs, RMI, sockets, SSL, etc.). To illustrate the implementation, several UML diagrams are included. The first UML sequence diagram shows how the Messaging design pattern is used to implement the Proxy design pattern. The second diagram shows how both design patterns are used to implement web services. The next diagram demonstrates how another communication interface is implemented by plugging in an additional component. The last diagram shows the implementation of secure web services. For clarity sake, the message sequence and the intrinsic processMessage() method have been removed from these diagrams.

Proxy implementation using the Messaging Design Pattern. The proxy forwards the message to the subject.

Web Service implementation using the Messaging Design Pattern.

Implementation of remote communication interfaces using the Messaging Design Pattern.

Note: Any other communication protocol/technology can be handled (Axis, EJB, RMI, sockets, SSL, etc). It is just a matter of replacing the HTTP Adapter and plugging in the appropriate adapter for the remote interface. The messaging design pattern and architecture make this possible. The other components remain unchanged. This design pattern solves a whole family of problems associated with remote APIs.

Secure web service implemented by plugging in a component to perform message encryption/decryption.

/**
         * Send a message to a remote component/Restful service using
         * a remote proxy. Secure/Encrypted messaging may be used.
         * The messaging design pattern provides transparent access
         * to remote components.
         */

        public static void main(String[] args) {

                JtFactory factory = new JtFactory ();
                String sReply;
                JtRestProxy proxy;
                String url = "http://localhost:8080/JtPortal/JtRestService";

                // Create an instance of the remote Proxy.

                proxy = (JtRestProxy) 
            factory.createObject (JtRestProxy.JtCLASS_NAME);

                proxy.setUrl(url);
                proxy.setClassname ("Jt.examples.Echo");

         // Specify that secure/encrypted messaging should be used.

                proxy.setEncrypted(true);

         // Send the message to the remote component/service via
         // the remote proxy.

                sReply = (String) 
            factory.sendMessage (proxy, "Welcome to Jt messaging ...");

          // The remote component will echo the input message.

                System.out.println ("Reply:" + sReply);


        },

Related design patterns:



Loading...