Reputation: 2551
In my app I want to use "local" message bus in a particular way (extended event emitter/observer/dispatcher):
bus.producers.register("topic/entity/get", ({id}) => entityClient.get(id));
Other component will post message in the bus:
bus.post("topic/entity/get", {id: 123});
and then consume the produced result;
What are the problems with this approach? Note: consumer component will have declarative metadata config with all messages in consumes and produces.
// get first produced (normal case)
const entity = await bus.getAsyncFirst("topic/entity/get", {id: 123});
// collect all entities from all producers
// rare case?
const entities = await bus.getAsync("topic/entity/get", {id: 123});
?
producer implementation just need to return value for consumer.
What are potential pitfalls of this? Or it is better to use generators for collecting all produced output (instead of Promise) Shoult I post message to bus as a result (instead of just returning result). Something like
bus.producers.register("topic/entity/get", ({id}) => {
const result = entityClient.get(id);
bus.post("topic/entity/get/result"); // *is it better? why?*
});
I can't find examples of such using of message bus.
Upvotes: 0
Views: 35