Skip to content

Client API

sskhiri edited this page Mar 14, 2012 · 19 revisions

Publisher API

The client API is at the boundaries of RoQ and let client caller send messages to queues.

//1. Creating the connection
IRoQConnectionFactory factory = new RoQConnectionFactory();
IRoQConnection connection = this.factory.createRoQConnection("logical_queue_name");
connection.open();
//2. Creating the publisher and sending message
IRoQPublisher publisher = this.connection.createPublisher();
publisher.sendMessage("sabri".getBytes(), "hello".getBytes()

Publisher API architecture

The architecture is shown by the Figure below.
The Publisher API architecture.

The RoQPublisherConnection manages the life cycle of the PublisherConnectionManager thread. This thread is responsible for targeting the right Exchange, it can be notified through the management channel by the monitor of the queue in order to re-allocate the publisher to another Exchange. This re-allocation can be caused by the Exchange failure or by the fact the Exchange is overloaded.

The close method on the RoQConnection will stop the PublisherConnectionManager thread.

Subscriber API

In the same way, the subscriber API needs a connection. This object will manage any topological changes of the logical queue. As a result, if an exchange is added or removed, the connection thread will re-configure the underlying connections. Exactly as the publisher connection, the subscriber connection must be opened and closed when the client caller finishes to send messages.

//1. Create with the factory, create the connection
IRoQSubscriberConnectionFactory subFactory = new RoQSubscriberConnectionFactory();
IRoQSubscriberConnection subConnection = subFactory.createRoQConnection("sabri");
//2. Open the connection to the logical queu
subConnection.open();
//3. Register a message listener
subConnection.setMessageSubscriber(new IRoQSubscriber() {
     public void onEvent(byte[] msg) {
     String content= new String(msg,0,msg.length) ;
     assert content.equals("hello");
       logger.info("In message lIstener recieveing :"+ content);
     }
});

Clone this wiki locally