如何在数据库中存储 pubsub 有效负载

发布于 2024-09-25 17:19:51 字数 1572 浏览 6 评论 0原文

我正在使用 XMPP pubsub。一切工作正常。用户可以创建节点,感兴趣的用户可以订阅该节点。但我想将发布操作存储到数据库中。因为在我的应用程序中,很多事情都是由 pubsub 处理的,例如聊天、提要等所以在页面刷新时我想保留聊天。所以我正在寻找任何将其保存到幕后数据库的 openfire 插件。就像openfire在MUC(多用户聊天)的情况下保存聊天一样。我不想手动发送ajax请求。那么有没有什么方法可以记录发布项目。

更新:

我的表单配置中有一个问题,其中持久项默认设置为 false。所以我按照您的建议配置了节点。但是我再次在页面刷新时遇到一些问题。我将用一个示例向您解释。在我的应用程序中,用户 A 登录并创建一个节点,成功创建后,它会向用户 B 发送请求,现在用户 B 订阅用户 A 创建的节点。现在,如果任何用户刷新页面,我会发送 get 类型的 IQ 节获取所有错过的事件,例如您上面提到的事件。但是我收到错误 400 subid-required。

<body rid='430432056' xmlns='http://jabber.org/protocol/httpbind' sid='dca8aafc'><iq to='pubsub.abc' type='get' xmlns='jabber:client' id='3408:sendIQ'><pubsub xmlns='http://jabber.org/protocol/pubsub'><items node='3821poU5zq7nhn1'/></pubsub></iq></body>

作为回应,我得到:

  <body xmlns='http://jabber.org/protocol/httpbind'><iq type="error" id="3408:sendIQ" from="pubsub.abc" to="test@abc/dca8aafc"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items node="3821poU5zq7nhn1"/></pubsub><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><subid-required xmlns="http://jabber.org/protocol/pubsub#errors"/></error></iq></body>

所以可以帮助我出错的地方。我还阅读了链接 http://xmpp.org/extensions/xep-0060.html#owner-configure 点:6.5.9.1 上面写着 如果请求实体对该节点有多个订阅但未指定订阅 ID,则服务必须向订阅者返回错误。那么这是否意味着我再次订阅同一个节点? 我检查了情况是否如此,但我只订阅一次。所以只是弄清楚哪里出了问题。

I am using XMPP pubsub.Everything is working fine.User can create node and interested user can subscribe to that node.But I want to store the publish action into DB.Because in my application many things are handled by pubsub like chat,feeds etc so on page refresh I want to persist chat.So I m looking for any openfire plugin which saves it into DB behind the scenes. Like openfire saves chat in case of MUC (Multiple User Chat).I dont want to manually send ajax request. So is there any way to log the publish items.

Update:

There was a problem in my form configuration in which persist items was set to false by default.So I configured the node as you suggested.But again I am facing some problem on page refresh.I will explain you with an example. In my application user A logs in and create a node and on successful creation it sends request to user B, now user B subscribe to the node created by user A.Now if any user does a page refresh I send an IQ stanza of type get to get all the missed events like the one you mentioned above.But I am getting error 400 subid-required.

<body rid='430432056' xmlns='http://jabber.org/protocol/httpbind' sid='dca8aafc'><iq to='pubsub.abc' type='get' xmlns='jabber:client' id='3408:sendIQ'><pubsub xmlns='http://jabber.org/protocol/pubsub'><items node='3821poU5zq7nhn1'/></pubsub></iq></body>

In response I am getting:

  <body xmlns='http://jabber.org/protocol/httpbind'><iq type="error" id="3408:sendIQ" from="pubsub.abc" to="test@abc/dca8aafc"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items node="3821poU5zq7nhn1"/></pubsub><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><subid-required xmlns="http://jabber.org/protocol/pubsub#errors"/></error></iq></body>

So can help me where I am getting wrong.Also I read the link http://xmpp.org/extensions/xep-0060.html#owner-configure point : 6.5.9.1 which says
If the requesting entity has multiple subscriptions to the node but does not specify a subscription ID, the service MUST return a error to the subscriber.So does it mean that I am subscribing to the same node again?
I checked if thats the case but I am subscribing only once.So just figuring out where things are getting wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2024-10-02 17:19:51

根据 XMPP 的 XEP-0060,PubSub 节点的所有者可以使节点上的项目在很远的将来过期。

创建节点时,您可能需要设置以下属性以使节点上的项目永不过期。

<field var='pubsub#persist_items' type='boolean' label='Persist items to storage'>
  <value>1</value>
</field>
<field var='pubsub#max_items' type='text-single' label='Max # of items to persist'>
  <value>999999</value>
</field>
<field var='pubsub#item_expire' type='text-single' label='Time after which to automatically purge items'>
  <value>999999999999</value>
</field>

来源:http://xmpp.org/extensions/xep-0060.html#owner -configure

然后,当您想要检索所有项目时,您可以这样做来检索数据:

<iq type='get'
    from='[email protected]/barracks'
    to='pubsub.shakespeare.lit'
    id='items1'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='princely_musings'/>
  </pubsub>
</iq>

来源:http://xmpp.org/extensions/xep-0060.html#subscriber-retrieve-requestall

这能解决您的问题吗?

Per XMPP's XEP-0060, it is possible for Owner of the PubSub node to make items on the node expire in a very distant future.

When creating a node, you may want to set the following attributes to make items on the node never expire.

<field var='pubsub#persist_items' type='boolean' label='Persist items to storage'>
  <value>1</value>
</field>
<field var='pubsub#max_items' type='text-single' label='Max # of items to persist'>
  <value>999999</value>
</field>
<field var='pubsub#item_expire' type='text-single' label='Time after which to automatically purge items'>
  <value>999999999999</value>
</field>

Source: http://xmpp.org/extensions/xep-0060.html#owner-configure

Then when you want to retrieve all the items, you can probably do this to retrieve the data:

<iq type='get'
    from='[email protected]/barracks'
    to='pubsub.shakespeare.lit'
    id='items1'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='princely_musings'/>
  </pubsub>
</iq>

Source: http://xmpp.org/extensions/xep-0060.html#subscriber-retrieve-requestall

Would this solve your problem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文