Get the source code for this video for FREE → the-dotnet-weekly.ck.page/microservices Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
MassTransit is a fantastic library. I had to build a quick POC and use RabbitMQ with Docker. Then we decided to replace RabbitMQ with Azure Service Bus with ease! Great video!
Nice. It would be great if you focused more on exchanges, queues, topic, fanouts. I’m service bus guy, so i hoped to learn more about using rabbit with massyransit
@@MilanJovanovicTech you definitely should mate, you have talent to explain everything in simple and practical manner without “water” and useless successful-success garbage
Thanks Milan. As always, your videos are top-notch. However, I can't find the playlist for this series so it is easy to follow from the start. Stay awesome! ❤
This is great. Do you think you could make a video about docker for this specific project? It would also be interesting to see how this could be deployed to AWS or Azure.
In many case's you can FireAndForget and not to wait for executing the second microservice. Kafka has this option maybe RabbitMQ can also. This is my opinion. Nice video, cheers.
This is doing that - when the publish to the queue completes, the initial request is done. It's also just instantly hitting the consumer breakpoint, so it might give that impression.
Great article. Do you think it's better to publish the event before the SaveChangesAsync in the DB and have a consumer in both apis to consume the message and use it to save the data ? Because with your aproach, if you loose the connection with your message broker, you loose your message and have a data problem (one db updated but not the other)? Or it's overkill ?
Always publish after it becomes a fact. So publish after SaveChanges is the only thing that makes sense. As far as reliability issues, there's the Outbox pattern for that.
You could put the message classes in both projects, but they could get out of sync that way. You don't want the service to reference each other for sure.
@@MilanJovanovicTech What do you think about these recommendations in this case? "The integration events can be defined at the application level of each microservice, so they are decoupled from other microservices, in a way comparable to how ViewModels are defined in the server and client. What is not recommended is sharing a common integration events library across multiple microservices; doing that would be coupling those microservices with a single event definition data library. You do not want to do that for the same reasons that you do not want to share a common domain model across multiple microservices: microservices must be completely autonomous. For more information, see this blog post on the amount of data to put in events. Be careful not to take this too far, as this other blog post describes the problem data deficient messages can produce. Your design of your events should aim to be "just right" for the needs of their consumers. There are only a few kinds of libraries you should share across microservices. One is libraries that are final application blocks, like the Event Bus client API, as in eShopOnContainers. Another is libraries that constitute tools that could also be shared as NuGet components, like JSON serializer." learn.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/integration-event-based-microservice-communications#integration-events
I think this is a limitation of masstransit, requiring same namespace for messages to be consumed. Requiring same namespaces on both ends is not “loosely coupled”
I rarely like or subscribe to video but this tops the charts, Do you offer tutoring one on one. I need to improve my skills and also have a close mentor close by.
Milan Thanks for the easy explanation. I am regulary following your videos and articles to implement the application architecture from scratch. I have few questions 1. How to handle multiple consumer for single event? eg. OrderCreated event to handle the reduce inventory, Update the counts for user order, product sellCount, etc... 2. Does the request wait untill all multiple event consumed..? 3. Is it mandatory to wait for response? eg. OrderCreated Email or SMS send..?
1. MassTransit takes care of it. You just write the consumers. And each handler will run concurrently. This is important to keep in mind. 2. No. It will just publish. Maybe there's a way to wait for ACK message (worth checking) 3. No
Great video. thank you. Could you please create something with container. 1 container containing multiple services and they interacting with each other. In this scenario can the MQ be outside the container? Thanks again!
Hi Milan, I really enjoy your tutorials, can you explain the distribution of database in microservices? for example customers, orders and products. It 's little bit unclear for me.
How do you handle data loss? For example after you publish some event (service A) and it is important, that other system/service (B) received this event. Let's say I stopped B service for update. What about such scenario?
@@MilanJovanovicTech i am not sure about masstransit but if you throw exceptions while handling the event in service B masstransit wont send ack to rabbitmq. Isn't that so?
Hello Milan! Thank you for the video. I watch all your videos and they are all awesome! I wanted to ask you what happens if the consumer for any reason is not running at the moment the message is sent. In that case, the consumer is going to be able to receive the message the moment it starts running again?
Amazing vídeo! If I need to getId from another context/domain, I would using the autorest integrated with my CI/CD and generate a sdk instead. It seems less work 😅. However, what are your thoughts about it?
This is the first time I've seen joining queries from different tables by doing a call in a call, thanks for showing this. Are there any negative effects to that the outer call being asynchronous and the inner call being synchronous? Also is this breaking principles if I would do this in domain driven design but with two aggregates?
The inner call isn't really a "call" - it just produces an IQueryable which EF can include in the expression tree. So it's just a single query at the end of the day.
@Milan what are your views on MassTransit vs Rebus? I just referenced your Saga Pattern video using Rebus for work. Now I woke up with more questions :)
Hi Milan, thanks for explanation. How about structuring consumer class in respect to Clean Architecture? According to my understanding from this video, it was in Application Layer (CMIIW), but for communication to the external layer, CA required us to place the code in Infrastructure layer.
I'll have to do a take two on this video. These days, I place the consumers in Presentation (like another endpoint). And only use them to send commands.
Great video. Thank you. How do you handle concurrency, if you want as example not consume messages by a consumer in parallel or only if some parameters are different?
@@MilanJovanovicTech Yes for 2 different messages I don't want the consumer to consume them in parallel as they will both change some data in the same database tables and it would be more efficient if I can avoid a DbConcurrencyException as the job is quite long.
Great video! Any plans on GraphQL HotChocolate content ? This could also be with microservices like Schema Stitching, Federation and the most recent one - HotChocolate Fusion
This is amazing!!! But if I want to consume only selected messages, I mean, How my application can consume only selected messages and leave others message in the queue
@@MilanJovanovicTech Fair enough. But, in this cause I would have used the Join method in the query rather than the context method you used. Although in resolution it might end up wit the same query. But, I'd prefer the join for code clarity.
Hey Milan, I'd like to know can we use AWS SQS instead of RabbitMQ as MassTransit. Or what is its equivalent on AWS? I am confused about how can we use pub-sub method with RabbitMQ. I think I have a concept and definition confusion.
I am facing problem in my project i will explain simple i have 2databases 1is master where i have ticketstatus tabel and i have ticket database where i am storing ticketstatusid in get tickets api u want to send ticketstatus data as well with tickets By now u might have understood these are 2different apis whats solution for this
I don't like MassTransit because it creates a wrapper around the message. If it were possible to pass the service data not in the wrapper but in the message header, it would be ideal.
Get the source code for this video for FREE → the-dotnet-weekly.ck.page/microservices
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
I landed a high paying role because of your content! I'm hoping to land an even higher paying one next year. Great video, awesome stuff as always!
This made my day! I'm very happy for you, mate. Keep crushing it! 🔥🔥
Milan is great.
Milan is my favorite knowledge transfer guy 🥰
Much appreciated!
MassTransit is a fantastic library. I had to build a quick POC and use RabbitMQ with Docker. Then we decided to replace RabbitMQ with Azure Service Bus with ease! Great video!
Did you run into any problems during that migration?
@@MilanJovanovicTech No issues at all. Keep in mind this is a new project, so it has not been put in production at all.
Heyy could u share the POC i need this
Thank you for taking the time to make this video, you are awesome!
Any time! :)
Thank you, Milan. All the best vibes from Slovenia!
Appreciate it! Sve najbolje iz Srbije :)
Bro thanks a lot, thanks to you I was able to solve a problem I've been stumped on for a week!
Glad I could help 😁
Great library
It's awesome 😁
Nice. It would be great if you focused more on exchanges, queues, topic, fanouts. I’m service bus guy, so i hoped to learn more about using rabbit with massyransit
That might end up being a "boring" video for most 😅
@@MilanJovanovicTech you definitely should mate, you have talent to explain everything in simple and practical manner without “water” and useless successful-success garbage
Thank you Milan. It's great content and very interesting.
My pleasure!
Thanks Milan.
As always, your videos are top-notch.
However, I can't find the playlist for this series so it is easy to follow from the start.
Stay awesome! ❤
This is the only video
Great! For next video Masstransit Saga ?
Great idea!
This is great. Do you think you could make a video about docker for this specific project? It would also be interesting to see how this could be deployed to AWS or Azure.
Yeah, that could be a nice idea
@@MilanJovanovicTech,it would be nice to see how to deploy rabbitMQ to Azure :)
I smashed the like button. It still looks awesome after being smashed. Greetings from Czechia!
Legend!
If we go with clean architecture which layer will your prefer to keep masstransit library? Will it it application or infrastructure layer?
Infrastructure
@@MilanJovanovicTech could you make video for it
In many case's you can FireAndForget and not to wait for executing the second microservice. Kafka has this option maybe RabbitMQ can also. This is my opinion. Nice video, cheers.
This is doing that - when the publish to the queue completes, the initial request is done. It's also just instantly hitting the consumer breakpoint, so it might give that impression.
Great article. Do you think it's better to publish the event before the SaveChangesAsync in the DB and have a consumer in both apis to consume the message and use it to save the data ? Because with your aproach, if you loose the connection with your message broker, you loose your message and have a data problem (one db updated but not the other)? Or it's overkill ?
Always publish after it becomes a fact. So publish after SaveChanges is the only thing that makes sense. As far as reliability issues, there's the Outbox pattern for that.
Excelent tutorial! Thxnz Milan!
You're welcome :)
nice video, will there be a video about event sourcing and saga patterns?
- Saga: th-cam.com/video/dlXCodLxhag/w-d-xo.html
- Saga compensation: th-cam.com/video/FPVzevl6Ri8/w-d-xo.html
I'll do a video on ES sooner or later
Will not using a shared class library with the contracts create a hard dependency between your services?
You need a way to keep the services using the same contract. Later on, it can be distributed as a NuGet package.
You could put the message classes in both projects, but they could get out of sync that way.
You don't want the service to reference each other for sure.
@@MilanJovanovicTech What do you think about these recommendations in this case?
"The integration events can be defined at the application level of each microservice, so they are decoupled from other microservices, in a way comparable to how ViewModels are defined in the server and client. What is not recommended is sharing a common integration events library across multiple microservices; doing that would be coupling those microservices with a single event definition data library. You do not want to do that for the same reasons that you do not want to share a common domain model across multiple microservices: microservices must be completely autonomous. For more information, see this blog post on the amount of data to put in events. Be careful not to take this too far, as this other blog post describes the problem data deficient messages can produce. Your design of your events should aim to be "just right" for the needs of their consumers.
There are only a few kinds of libraries you should share across microservices. One is libraries that are final application blocks, like the Event Bus client API, as in eShopOnContainers. Another is libraries that constitute tools that could also be shared as NuGet components, like JSON serializer."
learn.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/integration-event-based-microservice-communications#integration-events
I think this is a limitation of masstransit, requiring same namespace for messages to be consumed.
Requiring same namespaces on both ends is not “loosely coupled”
I rarely like or subscribe to video but this tops the charts, Do you offer tutoring one on one. I need to improve my skills and also have a close mentor close by.
I don't do 1-1 mentoring :)
Thank you Milan you are amazing
Thanks!
Great video,
Glad you enjoyed it
Milan
Thanks for the easy explanation. I am regulary following your videos and articles to implement the application architecture from scratch. I have few questions
1. How to handle multiple consumer for single event? eg. OrderCreated event to handle the reduce inventory, Update the counts for user order, product sellCount, etc...
2. Does the request wait untill all multiple event consumed..?
3. Is it mandatory to wait for response? eg. OrderCreated Email or SMS send..?
1. MassTransit takes care of it. You just write the consumers. And each handler will run concurrently. This is important to keep in mind.
2. No. It will just publish. Maybe there's a way to wait for ACK message (worth checking)
3. No
Good to se little bit longer videos focused more on software architecture
Plenty more to come!
Great video. thank you.
Could you please create something with container. 1 container containing multiple services and they interacting with each other. In this scenario can the MQ be outside the container? Thanks again!
Great suggestion!
Hi Milan, Where you added queue and exchanges configurations.
MassTransit takes care of that behind the scenes
@@MilanJovanovicTech can we handle multiple consumers using this mass transit?
Do i need to create complete docker-compose file or only the rabbitMq one?
You can run RabbitMQ independently, of course
Hi Milan, I really enjoy your tutorials, can you explain the distribution of database in microservices? for example customers, orders and products. It 's little bit unclear for me.
Basically you want every microservice to have its own database, holding the data required by that service
@MilanJovanovicTech when data is relational? Is it normal to have a full copy of tables into different databases according to microservices?
How do you handle data loss? For example after you publish some event (service A) and it is important, that other system/service (B) received this event. Let's say I stopped B service for update. What about such scenario?
It will queue up in RabbitMQ until service B is up again. If RabbitMQ is down you could use outbox pattern. I think milan has video for that as well.
Service B stops while handling the event?
@@MilanJovanovicTech i am not sure about masstransit but if you throw exceptions while handling the event in service B masstransit wont send ack to rabbitmq. Isn't that so?
@@ArinSinabian Yes, but I'm trying to clarify if that's what he meant
I would assume the message sits on the queue until its handled
Thanks for your awesome video mate,
It would be great if you create some videos about distributed tracing.
Will do!
Great content
Thanks!
very nice. thank you.
You're very welcome :)
Hello Milan! Thank you for the video. I watch all your videos and they are all awesome! I wanted to ask you what happens if the consumer for any reason is not running at the moment the message is sent. In that case, the consumer is going to be able to receive the message the moment it starts running again?
Yes
Is it possible to run the program after finishing work to see the results?
Yes
Very informative video! How would we normally share 'Contracts' between two applications in a real world project?
NuGet package
Milan, thank you for the awesome video!
Could you share what VS extensions you use?
I use ReSharper, Editor Guidelines, and Color Output for the build console highlighting
best structure and High perfomance
Thanks!
Milan can you make video on implementing oauth 1.0 and 2.0?
Maybe
Hi, Milan! Awesome and useful video! Do you always use primitives such as Result, Error and etc. in your projects?
Most of the time, yes
Amazing vídeo!
If I need to getId from another context/domain, I would using the autorest integrated with my CI/CD and generate a sdk instead. It seems less work 😅. However, what are your thoughts about it?
Seems like a nice idea
How do we ensure CreateArticle will save to the dbcontext AND the created event is published? Ie: make the operation atomic?
Outbox/Inbox
Great tutorial Milan! As a suggestion could you please cover how an API gateway could be implemented for this project? Maybe using Ocelot?
Great suggestion!
This is the first time I've seen joining queries from different tables by doing a call in a call, thanks for showing this. Are there any negative effects to that the outer call being asynchronous and the inner call being synchronous? Also is this breaking principles if I would do this in domain driven design but with two aggregates?
The inner call isn't really a "call" - it just produces an IQueryable which EF can include in the expression tree. So it's just a single query at the end of the day.
Why at 18:30 you fetching Events collection from another query instead of join & select from navigation property?
Because I'm not using a navigation property 🤷♂️
@Milan what are your views on MassTransit vs Rebus? I just referenced your Saga Pattern video using Rebus for work. Now I woke up with more questions :)
I think MassTransit is more powerful
may I know why the publisher class always have to be static ?
But it isn't? 🤔
Please make video about saga and apigateway 😊
- Saga: th-cam.com/video/dlXCodLxhag/w-d-xo.html
- Saga compensation: th-cam.com/video/FPVzevl6Ri8/w-d-xo.html
- YARP load balancer (can easily be extended to API gateway): th-cam.com/video/0RaH9hhOF4g/w-d-xo.html
Hi Milan, thanks for explanation. How about structuring consumer class in respect to Clean Architecture? According to my understanding from this video, it was in Application Layer (CMIIW), but for communication to the external layer, CA required us to place the code in Infrastructure layer.
I'll have to do a take two on this video. These days, I place the consumers in Presentation (like another endpoint). And only use them to send commands.
@@MilanJovanovicTech Noted. Thanks!
Great video. Thank you. How do you handle concurrency, if you want as example not consume messages by a consumer in parallel or only if some parameters are different?
Why is concurrency a problem here? (for different messages, for example) 🤔
@@MilanJovanovicTech Yes for 2 different messages I don't want the consumer to consume them in parallel as they will both change some data in the same database tables and it would be more efficient if I can avoid a DbConcurrencyException as the job is quite long.
How would you keep microservices decoupled if microservice A needs data from microservice B without a direct call to eachother?
Sent that data using a queue
Good content, question: Can MassTransit be used in a .net Minimal web api? Regards.
Yes, absolutely
Is this the same as domain events, a little confused on that
No, these would be integration events. Domain events are bound to a single domain. Integration events leave the boundary of a domain.
Great video! Any plans on GraphQL HotChocolate content ? This could also be with microservices like Schema Stitching, Federation and the most recent one - HotChocolate Fusion
No GraphQL planned at this point in time
This is amazing!!! But if I want to consume only selected messages, I mean, How my application can consume only selected messages and leave others message in the queue
What do you mean by this? Select types of messages?
Can you do comparison mass transit vs Rebus
Maybe 🤔
Would this work between .net framework and .net 8? Could I use masstransit to communicate back and forth?
In theory yes? It's just messages being sent over a message bus. But I can't say for sure.
Good information but you are not showing what is happening in RabbitMQ. For example: how many Queues were created? How to handle retries?
Noted
Awesome!
Thanks!
if we're using Aspire with RabbitMQ should we also use MassTransit with Aspire?
I think the question is "Should we use MassTransit with RabbitMQ"? 🤔
@@MilanJovanovicTech i think so. It's going to work dude
Can we replace masstransit with nservicebus
Yes
Why don't you map the Article and ArticleEvents relationship in the Consumer/Reporting Project? It would simplify your query.
I could've just exposed a navigation property sure. But in my mind, the ArticleEvents collection is unbounded so I opted not to do it.
@@MilanJovanovicTech Fair enough. But, in this cause I would have used the Join method in the query rather than the context method you used. Although in resolution it might end up wit the same query. But, I'd prefer the join for code clarity.
That's straight to the point, that's good. What's your opinion on calling microservices through http clients?
Perfectly acceptable integration pattern. I'll do a separate video discussing HTTP vs Messaging
Waiting for that 👍
If you are experienced with it, could you make a video on how we can use the actor model in DDD
I didn't work with the Actor model before, but I can make some introductory videos as I study the topic
Thank you for the nice video. How to find the host name of my rabbitmq ?
localhost if exposes, in docker network use container name
Hey Milan, I'd like to know can we use AWS SQS instead of RabbitMQ as MassTransit. Or what is its equivalent on AWS? I am confused about how can we use pub-sub method with RabbitMQ. I think I have a concept and definition confusion.
Yes, check here: masstransit.io/documentation/transports
Do they have a TH-cam Channel like yours but for Java? 😭
I'm not aware of it 😅
I am facing problem in my project i will explain simple i have 2databases 1is master where i have ticketstatus tabel and i have ticket database where i am storing ticketstatusid in get tickets api u want to send ticketstatus data as well with tickets
By now u might have understood these are 2different apis whats solution for this
Query both of them?
if you can please show how to implement synchronous communication with microservices 😋
HTTP?
Or grpc
The consumer reports an error, how to fix the system, how to re-execute
Retries, dead-lettering are some of the things you can do
@@MilanJovanovicTech
And now come failures... DB not vavailable, messages lost etc. With all that transactional outboxes, sagas and so on.
The fun of microservices :)
MassTransit or ServiceStack?
MassTransit
👋
I don't like MassTransit because it creates a wrapper around the message. If it were possible to pass the service data not in the wrapper but in the message header, it would be ideal.
Better build it all yourself 🤷♂️