Comments (5)
Hi @r3dsm0k3
Thanks for your feedback. Your current workaround is probably the simplest, though it does bypass the bus entirely. When using it, the library needs to be agnostic around its environment. The problem when trying to invoke a callback when the command finishes comes down to not being guaranteed where the command gets executed.
The command handler could be on another instance of the API, or could be sitting in a separate application service. In theses cases your command would leave the current node, traverse the message transport, be processed at some point (depending on the load of your message handling service) and an event/reply emitted.
Once the event is emitted, there's no way to ensure that the originating API instance will be the one who receives it - at least not in a pub/sub style setup. One way to achieve this is to enhance the library to support private ephemeral queues and enable a replyToSender()
function. This would allow a command handler to directly send a response to the sender of the command by placing the response in the sender's private queue.
The idea of a callback passed into send()
would work fine for a single-instance of a memory-queue, but the ultimate goal of this library is to provide the same functionality regardless of the size or setup of the underlying services.
I'll use this ticket to track .replyToSender()
and .replyTo()
functionality
from bus.
@adenhertog this would be awesome, I'm building a very API centric tool so it'd expand the places I can use this from a bit of the deep backend to almost all of it.
from bus.
Hey Ajith,
I think here you're talking about the request-response pattern of EIP messaging, ie: https://www.enterpriseintegrationpatterns.com/patterns/conversation/RequestResponse.html. This library has currently only implemented a pub-sub style so there's no way to await a bus-based response directly.
Implementing something like this wouldn't be too difficult and using it would be pretty similar to your example.
There may be an alternative depending on what's requesting your API. If your consumer is a web front end, would it be feasible to subscribe the resulting event via a websocket?
from bus.
Hi @adenhertog , thanks for the quick response.
I'm building a graphql api, which maybe consumed by web frontends or desktop applications or mobile apps. In this case, I'm registering a user and there's no way to respond with an error/registered user's uuid. We'd have to have another query for this. As I said, I currently work around this with not using the commandbus, but instead calling the commandhandler directly. From the library I'm only using the eventbus and the DDD modules. It would be really great if I could use all the features if there was a work around.
How about handing in an optional callback function along with the .send()
? It could get triggered after all the registered handlers have finished processing the message and bus can invoke it.
from bus.
Recently, I have applied a similar approach using Web sockets with the service bus. The command handler at the end of its execution would send a message through web socket and the API would wait for this message from web socket to resolve the promise.
from bus.
Related Issues (20)
- Errors thrown in workflows aren't visible
- Add workflow lifecycle hooks
- Provide a CLI option for queue migrations
- Construct workflows using container during mapping
- Port middleware over to master HOT 1
- RabbitMQ queue and exchange setup HOT 8
- The memory-queue is inappropriately deleting messages HOT 1
- Broken links in docs HOT 1
- Delay a retry by X seconds HOT 1
- Vulnerability in url-parse - dependency of amqplib HOT 1
- Rabbitmq transport polling HOT 2
- IoC with loopback HOT 4
- Named export <nameExport> not found HOT 2
- [bus-class-serializer]: package.json missing attributes HOT 1
- [Bug] Rabbitmq-transport.ts does not have reconnection if channel gets disconnected by some reasons
- How to setup DI container, when workflow needs the bus instance HOT 2
- Open to update `bus-sqs` to aws-sdk v3?
- Support Mognodb Persistence for Workflows
- RabbitMQ transport doesn't allow custom message headers. HOT 4
- Problem with lodash and persisting workflow state
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bus.