Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Registering WebSocket connections with NiFi

avatar

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

avatar

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!

View solution in original post

4 REPLIES 4

avatar

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!

avatar

Ah, gotcha. Will use that workaround - thanks!

avatar

avatar
Master 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.