Gateway to Client Communication (Push Notification)

Hi,

I try to send notification only to a specific client.

In SDK programmation guide Gateway to Client Communication (Push Notification) it’s possibly by the client registers itself with the module on the gateway through RPC, in order to provide the gateway with its session id, and the gateway then sends messages specifically for that client.

Unfortunately I don’t see how it can be possible.

Any suggestions or samples could be helpful :thinking:

Regards.

The key to this pattern is that the initial RPC method must create a persistent object that holds a reference to the session object, that can then be used to send out-of-band notifications to that client. Consider this sample, working code from my Time Series DB Cache Module:
GatewayRPC.java (4.8 KB)
When the client calls the register() function to set up a caching on a table, in addition to returning the handle the client will need to actually request data, the new cache is given a listener (nested class PushToClient) that holds the session reference.
When the client then calls getResult(), the cache can immediately return any matching data already cached, while triggering background acquisition of any missing data. When that data arrives asynchronously, the cache’s listener can deliver it to interested clients via PushToClient.newData().
The cache listener can also send the .forget() and .expired() cache management notices as needed.

Hi @pturmel,
where do you find the ClientReqSession reference ?
In the mocule client scope, the ClientContext reference passed in the AbstractClientModuleHook startup method don’t provide this reference ?
Could you please show us the way to obtain the ClientReqSession reference !

getRPCHandler(ClientReqSession session, java.lang.Long projectId) in the AbstractGatewayModuleHook seem to be the way…

Yes, you must implement the getRPCHandler() method in your GatewayHook. Like so in this case:

	@Override
	public Object getRPCHandler(ClientReqSession session, Long projectId) {
		return new GatewayRPC(session, projectId, new GatewayCache.Provider());
	}
2 Likes

OK, Thank you for all response.

I try to implement your solutions and I tell you next.

Perfect! Before your reponse, getrcphandler return a singleton instance and it was impossible to know the client session. Now it’s perfect. I am able to notify only one client session. Thanks @pturmel and @mazeyrat.

It’s just a starter Kit.cdgExchangeSample.zip (148.7 KB) with your suggestions

1 Like