1

So I'm not sure how to do this. I've done this using Quarkus and the MicroProfile Reactive Messaging framework and the javax.websocket library stuff but I'm not sure how I can port this to using Kafka Streams. With MP Reactive Messaging I can just have an @Outgoing annotation on a channel in one of my other classes and then with my WebSocket service I can inject from that channel like so.

@ServerEndpoint("/validatedmessages")
@ApplicationScoped
public class WebSocket {

@Inject @Channel("post-final-check") Flowable<CustomMessage> finalizedMessages;
//private Jsonb jsonb;
ObjectMapper obj = new ObjectMapper(); 

private static final Logger LOGGER = Logger.getLogger(WebSocket.class);

private List<Session> sessions = new CopyOnWriteArrayList<>();
private Disposable subscription;

@OnOpen
public void onOpen(Session session) {
    sessions.add(session);
}

@OnClose
public void onClose(Session session) {
    sessions.remove(session);
}

@PostConstruct
public void subscribe() {
    subscription = finalizedMessages.subscribe(message -> sessions.forEach(session -> {
        try {
            write(session, message);
        } catch (JsonProcessingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }));
}

@PreDestroy
public void cleanup() throws Exception {
    subscription.dispose();
    //jsonb.close();
}

Is it possible to do this with Kafka Streams?

animusdx
  • 380
  • 3
  • 16

1 Answers1

0

Where do you store your output of Kafka Streams ? In topics or KTable ?

If it is the first, then you can inject a Publisher or use @Incoming(topic). Otherwise you need to use InteractiveQueries, see here for an example:

https://quarkus.io/guides/kafka-streams#interactive-queries

Serkan
  • 639
  • 5
  • 14