powered by Jive Software

Subscribers are not getting event notification related to pubsub

I am new to XMPP and openfire, I trying to explore pubsub model of xmpp using openfire:

As a part of pubsub test I have followed following steps:

I have created connection with openfire using smack API.

Added Subscribers to node

Published items to node.

Event is getting fired.

But end user is not getting any notification(I am expecting notification either in the form of chat message of email).

Using openfire can I create node using admin console, subscribe users to it and pubish item to it?

Thanks,

Ujval

Your subscribers will need to listen specifically for the pubsub messages. You might want to try using this extension for doing your pubsub work.

There is no admin console for pubsub.

I am using the pubsub extension provided by smack. My code snippet is as follows:

// Setup event source

String nodeId =

PubSubManager creatorMgr =

“TestNode” + System.currentTimeMillis();

LeafNode creatorNode = getPubnode(creatorMgr, nodeId,

new PubSubManager(getConnection(0), getService());

BlockingQueue<ItemEventCoordinator<PayloadItem>> queue =

true, true);

new ArrayBlockingQueue<ItemEventCoordinator<PayloadItem>>(3);

// Setup event receiver

PubSubManager subMgr =

LeafNode subNode = (LeafNode)subMgr.getNode(nodeId);

ItemEventCoordinator<PayloadItem> sub1Handler =

new PubSubManager(getConnection(1), getService());

subNode.addItemEventListener(sub1Handler);

Subscription sub1 = subNode.subscribe(getConnection(1).getUser());

new ItemEventCoordinator<PayloadItem>(queue, “sub1”);

// Send event

String itemId = String.valueOf(System.currentTimeMillis());

String payloadString =

creatorNode.send(

“<book xmlns=“pubsub:test:book”>Sir Arthur Conan Doyle”;

new PayloadItem(itemId, new SimplePayload(“book”, “pubsub:test:book”, payloadString)));

ItemEventCoordinator<PayloadItem> coord = queue.take();

I am getting coord.events.getItems().size()=1. So, I am expecting notification to the subscriber in the form of chat message or email.

Here I am not clear, how openfire will send notification(message/email)?

Your message is being received by the the *ItemEventHandler *you registered, in this case it was sub1Handler. The *Item *delivered in the message can be retrieved by calling *coord.events.getItems().get(0) *in your particular example.

Here do I need to explicitely extract the payload and itemId associated with this item and send explicit notification to all the subscribers?

Here I was assuming that, since I have added the subscriber to the node, opefire will automatically send notification to him whenever we publish item to this node.

ujval.sanghavi wrote:

Here do I need to explicitely extract the payload and itemId associated with this item and send explicit notification to all the subscribers?

No, you don’t send anything yourself. As a client, you typically wouldn’t even know or care who other subscribers are since they are running in different instances of applications.

Here I was assuming that, since I have added the subscriber to the node, opefire will automatically send notification to him whenever we publish item to this node.

This is correct. Every subscriber should register its own *ItemEventListener *and then subscribe. Then each subscriber’s listener will get called whenever an Item is published. The item contains the id and payload.