Session: How to Get the Current Session Node

When working in a RavenDB cluster, a database can reside on multiple nodes. When the client needs to send a request to the server, it can have several nodes to choose from.

The choice of the node depends on the value of ReadBalanceBehavior, which is taken from the current conventions (read more about it here).

In order to find out what is the current node that the session sends its requests to, use the getCurrentSessionNode method from the advanced session operations.

Syntax

ServerNode getCurrentSessionNode();

Return Value

The return value of getCurrentSessionNode is a ServerNode object

public class ServerNode {
    private String url;
    private String database;
    private String clusterTag;
    private Role serverRole;

    // getters and setters
}

public enum Role {
    NONE,
    PROMOTABLE,
    MEMBER,
    REHAB
}

Example

ServerNode serverNode = session.advanced().getCurrentSessionNode();
System.out.println(serverNode.getUrl());