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?