Message sinks are somewhat simpler than message sources. A message sink must implement the atg.dms.patchbay.MessageSink
interface. This interface defines a single method, receiveMessage
, which is called to notify the message sink that a message is being delivered. This method might be called simultaneously by many threads, so the message sink should be coded accordingly. The following is a simple example of how a message sink might handle a message:
import atg.dms.patchbay.*; import javax.jms.*; ... public void receiveMessage (String pPortName, Message pMessage) throws JMSException { System.out.println ("Received message from port " + pPortName + " of JMSType " + pMessage.getJMSType ()); if (pMessage instanceof TextMessage) { System.out.println (" TextMessage, value = \"" + ((TextMessage) pMessage).getText () + "\""); } else if (pMessage instanceof ObjectMessage) { System.out.println (" ObjectMessage, value = \"" + ((ObjectMessage) pMessage).getObject () + "\""); } else if (pMessage instanceof MapMessage) { System.out.println (" MapMessage"); } else if (pMessage instanceof StreamMessage) { System.out.println (" StreamMessage"); } else if (pMessage instanceof BytesMessage) { System.out.println (" BytesMessage"); } }
This example just prints out a text string whenever it receives a message, including the port name (described in the Using Messaging Ports section of this chapter), the JMSType
, and some additional information depending on the actual subclass of the message.