mercredi 26 juin 2019

What's the best practice on async message handling

I'm implementing a websocket messaging client with netty and java8. Each message has a transactionId, correlate to its response.

I need to implement a send API. So I have a few options.

  1. send(message, Callback);
  2. CompletableFuture send(message);

Either way, I'm thinking to have a transaction map(hashmap), which contains transactionId to Callback or CompletableFuture mapping. My question is which one is a better practice? Or something else? Is it OK to put CompletableFuture into Map?

Any good design to solve a similar problem?

Aucun commentaire:

Enregistrer un commentaire