The messaging API of the WebORB Java Client enables the publish/subscribe-based model of exchanging data messages between Java applications and other supported client types. Additionally, the API can be used to exchange data messages between the server and Java applications. WebORB publish/subscribe messaging uses the concept of messaging destination. A messaging destination can be visualized as a pipe which can accept messages from publishers and distribute them to the subscribers. Additionally, destinations can be attached to various message queuing systems like JMS, WebSphere MQ or ActiveMQ. The diagram below illustrates how messaging clients, destinations and external messaging systems can interact for message delivery in a publish/subscribe scenario:

To learn more about messaging destinations, see the WebORB Messaging Destinations chapter.
The messaging API is available in weborb.client.WeborbClient class. Consider the following example. The example creates both a producer and consumer in the same application. There is a loop accepting messages from the user and publishing them into the destination. The code also subscribes to receive messages from the same destination and outputs them to the standard output stream:
package demo.weborbclient;
import weborb.client.Fault;
import weborb.client.IBasicMessagingResponder;
import weborb.client.Subscription;
import weborb.client.WeborbClient;
import weborb.exceptions.MessageException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MessagingClient
{
public static void main( String[] args ) throws Exception
{
WeborbClient client = new WeborbClient( "http://localhost:8080/weborb.wo", "ChatDestination" );
Subscription subscription = client.subscribe( new MySubscriptionResponder() );
System.out.println( "Press [Enter] to stop the program or type a message and press [Enter] to publish it" );
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
while( true )
{
System.out.print( "\n> " );
String message = reader.readLine();
if( message.length() == 0 )
break;
System.out.println( "\nPublishing message - '" + message + "'" );
client.publish( message );
}
subscription.unsubscribe();
}
}
class MySubscriptionResponder implements IBasicMessagingResponder
{
public void responseHandler( Object result ) throws MessageException
{
Object[] messages = (Object[]) result;
for( Object message : messages )
System.out.println( "Received message from destination - " + message );
}
public void errorHandler( Fault fault ) throws MessageException
{
System.out.println( "Received error - " + fault.getDetail() );
}
}
Publish/Subscribe Java Client API