I'm trying to add more functionality to the example of flink-statefun-playground/java/shopping-cart and have two questions:

1.How to implement the functionality of waiting for completion of multiple asynchronous messages.

For example, if Microservice A needs to send message b to multiple instances (B1, B2, B3) of Microservice B after A receiving message a. Each instance of B returns message c to A after processing message b. A can proceed only when it receives message c from all instances of B (B1, B2, B3). How should I handle this?

My current idea is to use a state variable in A to track the received message list (e.g., {"B1": "not received", "B2": "received", "B3": "not received"}). A can proceed when all values in the message list are marked as "received". However, I'm concerned about efficiency, especially if A may receives new messages a while waiting. Does StateFun provide support for handling the completion of multiple asynchronous messages efficiently in Java, or do you have any suggestions?

2.How to achieve full exact-once semantic.

As README in shopping cart example mentions, "This example uses an egress in exactly-once mode." How and where is this explicitly declared and ensured in the example? Besides, In the example, should we also add a replayable event source for ingress like Kafka to achieve this exact-once guarantee? Otherwise, how does this semantics work if the request is lost?

Thank you for your assistance!

0

There are 0 best solutions below