I am trying to understand different methods used in messaging between services.
Let us say that I have a scenario where I need first service to notify the other that a user has asked for product creation, and the second service should receive this message, create a product and then respond telling the first service that a product has been created.
I am thinking that commands along with request/respond suits this scenario because the first service will need to address another specific service and will wait for feedback.
My understanding is that:
Events vs commands:
Events:
Commands:
Request/Respond vs Publish/Subsribe:
Request/Respond:
In Request/Respond the first service requests from the other to perform an operation and waits until respond is returned from the later.
Publish/Subscribe:
First service just publish a message and continue processing without waiting for feedback or response.
Now I started to design the messaging system using RabbitMQ along with Masstransit saga (Masstransit.Automatonymous) which seems to follow Events with publish/subscribe methods.
My Question is:
can I use commands with publishing or events with request/respond?
Is my understanding correct? and can sagas be used with request/response?
In general, your understanding is correct. However, I will summarise here too:
MassTransit sagas with Automatonymous support any type of message processing. You need to map all messages that saga consumes as state machine events, but these can be both commands and events - technically it doesn't matter. Sagas can publish and send messages, also can send requests and wait for replies.
As you question about publishing commands and using events for request-response. Techicanlly, MassTransit has no distinction in message types. Everything you publish is an event. Stuff you send can be a command or it can be something else, but this is not an event. When you use request-response, you have to send to a specific endpoint, so definitely this is not an event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With