A client session can send a request message containing typed data directly
to each client session in the set of connected client sessions that match a specified
session properties filter. The receiving client sessions can then send a response message
containing typed data. The request and response messages are addressed through the same
Note: Sending messages to a set of client sessions defined by a filter is not intended for high
throughput of data. If you have a lot of data to send or want to send data to a lot
of client sessions, use the pub-sub capabilities of Diffusion™ Cloud.
Subscribe the set of client sessions to a topic and publish the data as updates through that
When a request message is sent to a set of client sessions and those sessions
respond, the following events occur:
A control client session sends a request message, specifying the filter that selects
the client sessions to receive the request and specifying the message path
to send the message through.
Diffusion Cloud evaluates the query and sends the message on to connected client
sessions whose session properties match the filter
The client sessions in the filtered set each receive the request message
through a request stream.
Each client session uses a responder to send a response to the request
The control client session receives responses from each of the clients sessions
specified by the filter.
The request messages and the response messages contain typed values. The messages can
contain data of one of the following types: JSON, binary, string, 64-bit integer, or
double. The response messages are not required to be the same data type as the
request or as the response messages from other client sessions.
Sending a request message to a filter
Required permissions:send_to_session permission for the
specified message path and register_handler permission
Usually, it is a control client session in your organization's backend that sends messages to
a filter. For more information about defining a session filter, see Session filtering.
Send the request message specifying the following information:
The query to use to filter which client sessions to send the requests
The message path to send the request and receive the responses through
//Establish control sesssion
final Session control = Diffusion.sessions().principal("control").password("password").open("ws://localhost:8080");
//Obtain the MessagingControl feature
final MessagingControl messagingControl = control.feature(MessagingControl.class);
//Create a JSON object to send as a request
final JSON request = Diffusion.dataTypes().json().fromJsonString("\"hello\"");
//Send the request to a message path "foo", to all sessions which do not have a 'control' principal and wait for (at most) 5 seconds until the response (number of responses) is received.
final int numberOfResponses = messagingControl.sendRequestToFilter("$Principal NE 'control'", "foo", request, JSON.class, JSON.class).get(5, TimeUnit.SECONDS);
Responding to messages sent to a filter
Required permissions:send_to_message_handler for the
specified message path
To the receiving client session, a request message sent to a filter is the same as a
request message sent directly to the session. The receiving client session responds
in the same way.