【问题标题】:Publishing an item with Payload to a Pubsub node using Smack使用 Smack 将带有 Payload 的项目发布到 Pubsub 节点
【发布时间】:2012-04-02 15:40:09
【问题描述】:

我正在尝试使用 Smack 将带有有效负载的项目发布到 pubsub 节点,但到目前为止我还没有成功。我已经创建了节点并将其配置设置为传递有效负载 (setDeliverPayloads=true)。我正在使用 send 方法发送带有有效负载的项目。

 node.send(new PayloadItem(this.clientNodeName+"*" + System.currentTimeMillis(), new SimplePayload("my book", "books:pubsub:simple", "")));

尽管如此,该项目是在没有有效负载的情况下发布的。构造的 IQ 也没有有效负载。正如我从 smack 的调试面板中看到的那样

这是 smack 构造并发送到 pubsub 服务的(显然没有负载)

<iq id="1ha20-11" to="pubsub.127.0.0.1" type="set">
   <pubsub xmlns="http://jabber.org/protocol/pubsub">
   <publish node="autoIncrement">
       <item id="autoIncrement*1333380921970"/>
   </publish>
  </pubsub>
</iq>

对于解决此问题的任何帮助,我将不胜感激。当然,我仍然可以使用原生 IQ 消息,但我会尽量避免这种情况,以尽可能使用 smack API 中的 PubSubManager。

【问题讨论】:

    标签: xmpp publish-subscribe openfire smack whack


    【解决方案1】:

    上面的代码没有任何问题。唯一的问题是上面提供的示例确实有一个空的有效负载 (SimplePayload("my book", "books:pubsub:simple", "")),因此 smack 甚至根本不显示该项目的有效负载。

    一旦指定了有效负载,它将被包含在已发布的项目中。

    这里是发布带有有效负载的项目的代码

      node.send(new PayloadItem(this.clientNodeName+"*" + System.currentTimeMillis(), new SimplePayload(load, "stage:pubsub:simple", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
    

    这是发送到 Jabbered 服务器的预期 IQ

    <iq id="OIqU4-12" to="pubsub.stage.127.0.0.1" type="set">
          <pubsub xmlns="http://jabber.org/protocol/pubsub">
            <publish node="autoIncrement">
              <item id="autoIncrement*1333438199718">
                <book xmlns="pubsub:test:book">
                  <title>Lord of the Rings</title>
                </book>
              </item>
        </publish>
      </pubsub>
    </iq>
    

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2011-02-18
      相关资源
      最近更新 更多