0

Here is my use case, user subscribe to my stream using websocket (GraphQl with subscription), I need to return an instance of org.reactivestreams.Publisher (which should be my kafka topic subscription) filtering message by user id.

To illustrate, something like this:

/ **
  *  I don“t know how to get a instance of Publisher<Balance>
  *  It should be a consumer from a kafka topic
  */
fun balance(myStream: Publisher<Balance>, userId: String): Publisher<Balance> {
    return myStream.filter { it.userId == userId }
}
Guilherme Torres Castro
  • 15,135
  • 7
  • 59
  • 96

1 Answers1

0

Maybe you need to write a Spring Cloud Stream consumer and then publish it to WebSocket programmatically. Something along the lines of

public Consumer<Flux<Balance>> myStream() {

  //filter here and then publish to websocket.

}

Here is an example of a WebSocket sink implementation that you can potentially use as a guide, but this is not reactive.

sobychacko
  • 5,099
  • 15
  • 26