1

Is there any way to send messages directly from KTable to websocket in Kafka?

I have data that are constantly updating. I keep them in Kafka compacted topic. When new websocket customer arrive I would like to send him a current state of my data, and then I want to send him automatically every change of the data. I believe that the best way it would be to somehow bind KTable (or GlobalKTable, or some state store maybe) with websocket. Is something like that possible?

Tomek
  • 11
  • 1
  • Does each of your record in KTable associate with an user? can you give an example? thanks! – Tuyen Luong Apr 19 '20 at 08:07
  • No. Every user suppose to receive the same data. For example we have a game and every user score some points. I would like to send to all the users entire High Score table with all the users scores. The entire high score is very big and I want to sent it only once, later I want to send only updates. – Tomek Apr 19 '20 at 14:43
  • So my idea was to somehow bind GlobalKTable which contains the current HighScore table with WebSocket in a way that GlobalKTables's updates will be send automatically to the websocket – Tomek Apr 19 '20 at 14:46
  • So all of the records will send to all users? you can use `KTable#toStream()` to get a KStream which have a record each time KTable is updated. But I'm not sure it relevant with your use case. – Tuyen Luong Apr 20 '20 at 01:52
  • It works for updates, but it does not help with sending start state. The idea is that when client connect I do 2 things: 1) sent to him current(most recent) state of my KTable. 2) subscribe him for updates of this table. When I make a stream from KTable I will be able to send to client every updates, but he needs a current state to start witch. Of course I can send to him statestore related with KTable. The problem is, that I am afraid of synchronization. I do not know how to make sure, that I will not lost any updates between sending a current (start) state and subscribe to KTable stream – Tomek Apr 20 '20 at 05:19

0 Answers0