Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Registering WebSocket connections with NiFi

Solved Go to solution

Registering WebSocket connections with NiFi

I’m working with NiFi WebSocket processors, and I’d like to update connected clients as data makes its way through the flow. Is there a way to register WS connections in such a way where once data makes its way to a PutWebSocket processor, I can push to all registered clients automatically?

Is this outside the scope of what NiFi may have been intended for?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Registering WebSocket connections with NiFi

Hi Edgar,

Currently, PutWebSocket processor needs an incoming flow file having a WebSocket session id attribute to tell the NiFi WebSocket server which connected client to send a message to.

I have tested a flow explained in this Gist to pull messages from Kafka then send it back to multiple connected clients.

https://gist.github.com/ijokarumawak/60b9ab2038ef906731ebf4c0eee97176

The flow does work, but it keeps flow files floating around in the loop and basically too difficult to setup.

The list of connected session ids are kept in WebSocket server controller service, so, theoretically it's possible to loop through those sessions in controller service without passing a specific session id from PutWebSocket processor. Maybe we can improve PutWebSocket processor so that it can send messages to every connected client.

I will create a JIRA for this improvement, in the meanwhile, please use the workaround like the above example flow.

Thanks!

4 REPLIES 4

Re: Registering WebSocket connections with NiFi

Hi Edgar,

Currently, PutWebSocket processor needs an incoming flow file having a WebSocket session id attribute to tell the NiFi WebSocket server which connected client to send a message to.

I have tested a flow explained in this Gist to pull messages from Kafka then send it back to multiple connected clients.

https://gist.github.com/ijokarumawak/60b9ab2038ef906731ebf4c0eee97176

The flow does work, but it keeps flow files floating around in the loop and basically too difficult to setup.

The list of connected session ids are kept in WebSocket server controller service, so, theoretically it's possible to loop through those sessions in controller service without passing a specific session id from PutWebSocket processor. Maybe we can improve PutWebSocket processor so that it can send messages to every connected client.

I will create a JIRA for this improvement, in the meanwhile, please use the workaround like the above example flow.

Thanks!

Re: Registering WebSocket connections with NiFi

Ah, gotcha. Will use that workaround - thanks!

Re: Registering WebSocket connections with NiFi

Re: Registering WebSocket connections with NiFi

Super Guru

https://community.hortonworks.com/articles/73833/an-example-websocket-application-in-apache-nifi-11....

if they are connected to the websocket you can send them information from the flow.

You could also package that information into KAFKA or JMS and send them to a queue and a backend will pull from the queue and send the WebSocket messages. That is probably more common to connect to the front end web.