Subject: PubSub - can't get subscription working, even stops *all* messages when attempted
I'm new to XMPP, but am extremely intrigued by all the possibilities it offers, particularly in the arena of publish/subscribe models of communication.
I have ejabber2 installed and running locally on my computer. I grabbed a XMPP supporting chat client (Miranda) and created a simple C# client using this wonderful AG Software SDK. I can send basic chat messages between these two clients without problems, presence is visible, etc.
I implemented the C# client/bot to respond with random numbers if I chat "rand" to it. Works great.
So I wanted to implement a pubsub example such that if the user subscribes to a specific node, they'll get random numbers every 10 seconds, published by this highly advanced bot.
So, in my bot, I do something like this:
And then I kick off a System.Threading.Timer to call a method which generates the random number, every 10 seconds:
To subscribe, I did the following:
I do *not* get the random number messages when published by the bot. And the even stranger thing is - if I execute that subscription code above, the C# client stops receiving messages from my Miranda client at all. And if I look in my ejabberd web manager, I can see the messages queuing up for when the bot comes online. If I don't execute that code (comment it out), messages still go through just fine even with that bot firing publish messages every 10 seconds on the Timer thread.
I can see my random number generator sending messages when I hook the OnXmlWrite event, and I see this:
I also tried swapping the Jid's used in the Subscribe method call, in case I mixed those up.
So, my questions then are:
1) When I create a node/publish to a node, do I need to specify a fully qualified path, including the server? Or should it just be "/rand/get"
2) Is it even possible to subscribe another user this way to a pubsub node? Or does the requesting user have to make the request?
3) Is it possible to subscribe to your own pubsub? In other words, can my bot publish the random number, but also subscribe such that it gets those messages? (just curious on that one - it seems like it should)
4) What am I doing wrong?
Edit: I moved the Subscription code to execute prior to the XMPPClient.Open(), and it doesn't have that strange problem where it stops accepting messages now. But why would it matter when the connection is open?
I have ejabber2 installed and running locally on my computer. I grabbed a XMPP supporting chat client (Miranda) and created a simple C# client using this wonderful AG Software SDK. I can send basic chat messages between these two clients without problems, presence is visible, etc.
I implemented the C# client/bot to respond with random numbers if I chat "rand" to it. Works great.
So I wanted to implement a pubsub example such that if the user subscribes to a specific node, they'll get random numbers every 10 seconds, published by this highly advanced bot.
So, in my bot, I do something like this:
PubSubManager manager = new PubSubManager(m_Client.XMPP);
Jid bot = new Jid("bot@mycomputername.mycomputerdomain.com");
manager.CreateNode(bot, "mycomputername.mycomputerdomain.com/rand/get");
Jid bot = new Jid("bot@mycomputername.mycomputerdomain.com");
manager.CreateNode(bot, "mycomputername.mycomputerdomain.com/rand/get");
And then I kick off a System.Threading.Timer to call a method which generates the random number, every 10 seconds:
Item item = new Item();
item.Value = (m_Random.Next(100) + 100).ToString();
PubSubManager manager = new PubSubManager(m_Client.XMPP);
manager.PublishItem(new Jid("bot@mycomputername.mycomputerdomain.com"), "mycomputername.mycomputerdomain.com/rand/get", item);
item.Value = (m_Random.Next(100) + 100).ToString();
PubSubManager manager = new PubSubManager(m_Client.XMPP);
manager.PublishItem(new Jid("bot@mycomputername.mycomputerdomain.com"), "mycomputername.mycomputerdomain.com/rand/get", item);
To subscribe, I did the following:
PubSubManager manager = new PubSubManager(client.XMPP);
manager.Subscribe(
new Jid("bot@mycomputername.mycomputerdomain.com"),
new Jid("miranda_user@mycomputername.mycomputerdomain.com"),
"mycomputername.mycomputerdomain.com/rand/get",
new IqCB((sender, iq, data) => Console.WriteLine("Recieved!") ));
manager.Subscribe(
new Jid("bot@mycomputername.mycomputerdomain.com"),
new Jid("miranda_user@mycomputername.mycomputerdomain.com"),
"mycomputername.mycomputerdomain.com/rand/get",
new IqCB((sender, iq, data) => Console.WriteLine("Recieved!") ));
I do *not* get the random number messages when published by the bot. And the even stranger thing is - if I execute that subscription code above, the C# client stops receiving messages from my Miranda client at all. And if I look in my ejabberd web manager, I can see the messages queuing up for when the bot comes online. If I don't execute that code (comment it out), messages still go through just fine even with that bot firing publish messages every 10 seconds on the Timer thread.
I can see my random number generator sending messages when I hook the OnXmlWrite event, and I see this:
<iq id="agsXMPP_5" type="set" to="bot@mycomputername.mycomputerdomain.com"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publishnode="mycomputername.mycomputerdomain.com/rand/get"><item>176</item></publish></pubsub></iq>
I also tried swapping the Jid's used in the Subscribe method call, in case I mixed those up.
So, my questions then are:
1) When I create a node/publish to a node, do I need to specify a fully qualified path, including the server? Or should it just be "/rand/get"
2) Is it even possible to subscribe another user this way to a pubsub node? Or does the requesting user have to make the request?
3) Is it possible to subscribe to your own pubsub? In other words, can my bot publish the random number, but also subscribe such that it gets those messages? (just curious on that one - it seems like it should)
4) What am I doing wrong?
Edit: I moved the Subscription code to execute prior to the XMPPClient.Open(), and it doesn't have that strange problem where it stops accepting messages now. But why would it matter when the connection is open?
This post was edited on 2009-07-15, 23:53 by Orion.