XMPP Smack API RosterListener +数据库更改

时间:2022-09-15 19:53:59

I'm writing an XMPP client in Java using the Smack API.

我正在使用Smack API在Java中编写XMPP客户端。

I registered a roster listener for each user, and the Smack API calls...

我为每个用户注册了一个名册监听器,并且Smack API调用了......

public void entriesAdded(Collection arg0) {}

... each time it notices a roster addition.

......每次注意到一个名册的加入。

Does anyone know if this listener will be set off if the database changes but not through the Smack API createEntry() method?

有没有人知道如果数据库发生更改而不是通过Smack API createEntry()方法,是否会启动此侦听器?

Basically, I want to tie the XMPP client to a website. When you add someone to the website friends list, I want the site to notify the client. Rather than setting up sockets or using PHP to log into the XMPP server, I was hoping that just modifying the database would work.

基本上,我想将XMPP客户端绑定到一个网站。当您将某人添加到网站朋友列表时,我希望该网站通知客户端。我没有设置套接字或使用PHP登录XMPP服务器,而是希望只修改数据库就行了。

Will this work or is there another way to handle this without the client constantly polling the database for changes?

如果没有客户端不断轮询数据库以进行更改,这是否可行或是否有另一种方法来处理此问题?

1 个解决方案

#1


Changing the database has nothing to do with Smack directly, since it is a client library. It has no database. The database will be used and accessed by the server, and depending on the server, there may be features that will allow the server to post messages when the db has been changed. I don't know if any xmpp servers actually have this feature.

更改数据库与Smack没有任何关系,因为它是一个客户端库。它没有数据库。服务器将使用和访问数据库,并且根据服务器的不同,可能存在允许服务器在更改数据库时发布消息的功能。我不知道是否有任何xmpp服务器实际上有这个功能。

You should check the capabilities of the server you are using, and possibly use extensions in the server itself to add the roster entries. Changing the database directly doesn't really sound like the way to go, as you will most likely have your XMPP server and database out of sync.

您应该检查您正在使用的服务器的功能,并可能使用服务器本身的扩展来添加名单条目。直接更改数据库听起来不太合适,因为您很可能会使您的XMPP服务器和数据库不同步。

As for the client polling the database, it doesn't sound like a good idea for the client to be able to directly access the database if it is being used by an XMPP server and potentially your webserver.

至于客户端轮询数据库,如果客户端能够直接访问数据库(如果XMPP服务器和可能是您的Web服务器正在使用它),这听起来不是一个好主意。

#1


Changing the database has nothing to do with Smack directly, since it is a client library. It has no database. The database will be used and accessed by the server, and depending on the server, there may be features that will allow the server to post messages when the db has been changed. I don't know if any xmpp servers actually have this feature.

更改数据库与Smack没有任何关系,因为它是一个客户端库。它没有数据库。服务器将使用和访问数据库,并且根据服务器的不同,可能存在允许服务器在更改数据库时发布消息的功能。我不知道是否有任何xmpp服务器实际上有这个功能。

You should check the capabilities of the server you are using, and possibly use extensions in the server itself to add the roster entries. Changing the database directly doesn't really sound like the way to go, as you will most likely have your XMPP server and database out of sync.

您应该检查您正在使用的服务器的功能,并可能使用服务器本身的扩展来添加名单条目。直接更改数据库听起来不太合适,因为您很可能会使您的XMPP服务器和数据库不同步。

As for the client polling the database, it doesn't sound like a good idea for the client to be able to directly access the database if it is being used by an XMPP server and potentially your webserver.

至于客户端轮询数据库,如果客户端能够直接访问数据库(如果XMPP服务器和可能是您的Web服务器正在使用它),这听起来不是一个好主意。