Project

General

Profile

Is it possible to use Redis as a DB for SessionManager?

Igor Khomenko
Added about 3 years ago

Is it possible to use Redis as a DB for SessionManager?

For example, we use Tigase cluster and would like to have a way to understand whether a user online or not.

At the moment the information of sessions is not shared between nodes, each node has its own in-memory storage of sessions.

and we have to ask each node to understand this information.


Replies (8)

Added by Wojciech Kapcia TigaseTeam about 3 years ago

Igor Khomenko wrote:

Is it possible to use Redis as a DB for SessionManager?

For example, we use Tigase cluster and would like to have a way to understand whether a user online or not.

At the moment the information of sessions is not shared between nodes, each node has its own in-memory storage of sessions.

This is not exactly true and depends on the clustering implementation that you are using. If you are using ACS (i.e. @tigase.cluster.strategy.OnlineUsersCachingStrategy@) then it caches information about all connections therefore making it available on all nodes and the ad-hoc will return information about all connected resources and nodes to which they are connected.

Added by Steffen Larsen about 3 years ago

Hmm just following this thread. I've just made a simple groovy script that I hit form the REST interface:

@def sessions = (Map)userSessions

XMPPSession session = sessions.get(BareJID.bareJIDInstanceNS(userJid))

if (session == null) {

    return ""

} else {

    List<XMPPResourceConnection> conns = session.getActiveResources()

    String conns_str = ""

    for (XMPPResourceConnection con: conns) {

        conns_str += "" + con.getJID() + " : " + con.getPresence() + ","

    }

    return conns_str

}

@

And this only give me the active resources on that specific node that I am making the request on. So if I make a REST request on node1 and If I have 3 clients connected. one on node1 and two clients on node2. Then I would expect to get all 3 active resources back - but I only get one??

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam about 3 years ago

You are correct, userSessions variable contains only users sessions which are connected to this cluster node.

As Wojciech mentioned information about all connections is available if you use tigase.cluster.strategy.OnlineUsersCachingStrategy and that is because this information is kept internally by ACS and tigase.cluster.strategy.OnlineUsersCachingStrategy to be precise. Instance of this class is available in adhoc scripts for SessionManager as variable named clusterStrategy and it implements interface @ClusteringStrategyIfc@, so you can use any method available in this interface to access data kept by this class.

Added by Steffen Larsen about 3 years ago

Ah so calling:

@

var clientSessions = clusterStrategy.getConnectionRecords(mybare@jid.dk);

@

Will give me all the sessions for a given bareJID?

/Steffeb

Added by Steffen Larsen about 3 years ago

It seems to work. but then how do I get a current presence for a given JID?

Because from the XMPPResourceConnection I can get it directly. I only have the ConnectionRecords and hence the JIDs when I am using the clusterStragety.getConnectionRecords method.

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam about 3 years ago

By default in ACS it is not possible to retrieve current presence for particular connection, however it is possible to get number of connections, list of full JIDs of connected clients and cluster node to which connection is established.

With additional configuration of ACS (which increases memory usage) and use of internal API of ACS it is also possible to retrieve current presence for every connection.

Added by Steffen Larsen about 3 years ago

Hi,

OK. how is this configure and where is the doc? If its too complicated I might just stick with asking every node in the cluster.. but still .. this make is cumbersome to add or remove nodes. :-/

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam about 3 years ago

To configure ACS to cache presence you need to add following line to etc/init.properties file:

sess-man/cluster-strategy-presence-cache=true

In ACS we use ConnectionRecordExt class which extends ConnectionRecordIfc@. This extended class contains @getLastPresence() method - see http://docs.tigase.org/tigase-acs/snapshot/javadoc/tigase/server/cluster/strategy/ConnectionRecordExt.html#getLastPresence--

    (1-8/8)