powered by Jive Software

PubSub Hello World not working

smack 3.2.2

ejabberd 2.1.10

this is my code:

ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222);  con = new XMPPConnection(config);  con.connect();  con.login("lutas", "111111");  PubSubManager manager = new PubSubManager(con, "pubsub."+con.getServiceName());
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(true);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open); LeafNode myNode = manager.createNode("TestNode-ot121");
myNode.sendConfigurationForm(form); SimplePayload payload = new SimplePayload("book","pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>");
PayloadItem item = new PayloadItem("item-nnn", payload);
// Required to recieve the events being published
myNode.addItemEventListener(new ItemEventListener<Item>() {   @Override
     public void handlePublishedItems(ItemPublishEvent<Item> arg0) {
                               System.out.println(arg0);
     }
  }); // Publish item
myNode.send(item); myNode.addItemEventListener(new ItemEventListener<Item>() {   @Override
  public void handlePublishedItems(ItemPublishEvent<Item> i) {
         System.out.println(i);
      }
});
myNode.subscribe("lutas@localhost");

I set the elementName and namespace is empty, the was successful.

I do not know the elementName and namespace can play a role.

like this:

SimplePayload payload = new SimplePayload("","", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>");
PayloadItem item = new PayloadItem("item-nnn", payload);

消息编辑者为:Lutas

I believe ejabberd has some constraints on its node ids in that they have to be named in a hierarchical fashion, like a file path. You may want to check out their forums for those conventions.