How To Build Loosely Coupled Microservices With MassTransit

Поділитися
Вставка
  • Опубліковано 3 січ 2025

КОМЕНТАРІ • 175

  • @MilanJovanovicTech
    @MilanJovanovicTech  Рік тому +5

    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

  • @rezvlt9285
    @rezvlt9285 Рік тому +25

    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!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +6

      This made my day! I'm very happy for you, mate. Keep crushing it! 🔥🔥

    • @PaulA-c4x
      @PaulA-c4x 17 днів тому

      Milan is great.

  • @kinggrizzly13
    @kinggrizzly13 Рік тому +11

    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!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Did you run into any problems during that migration?

    • @kinggrizzly13
      @kinggrizzly13 Рік тому

      @@MilanJovanovicTech No issues at all. Keep in mind this is a new project, so it has not been put in production at all.

    • @vaibhavvatsa2571
      @vaibhavvatsa2571 3 місяці тому

      Heyy could u share the POC i need this

  • @vallJune
    @vallJune 11 днів тому +1

    Milan is my favorite knowledge transfer guy 🥰

  • @hattinnh
    @hattinnh 7 місяців тому +1

    Thank you for taking the time to make this video, you are awesome!

  • @mistguides
    @mistguides Рік тому +1

    Thank you, Milan. All the best vibes from Slovenia!

  • @ryoman76
    @ryoman76 Рік тому +16

    Great! For next video Masstransit Saga ?

  • @sauravbhatta5303
    @sauravbhatta5303 Рік тому +4

    Great library

  • @kodindoyannick5328
    @kodindoyannick5328 9 місяців тому +1

    Thank you Milan. It's great content and very interesting.

  • @AkashKarve-t2o
    @AkashKarve-t2o 10 місяців тому +1

    If we go with clean architecture which layer will your prefer to keep masstransit library? Will it it application or infrastructure layer?

  • @gretings
    @gretings 6 місяців тому +1

    Bro thanks a lot, thanks to you I was able to solve a problem I've been stumped on for a week!

  • @zikkrype
    @zikkrype 10 місяців тому +4

    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
      @MilanJovanovicTech  10 місяців тому +1

      That might end up being a "boring" video for most 😅

    • @zikkrype
      @zikkrype 10 місяців тому

      @@MilanJovanovicTech you definitely should mate, you have talent to explain everything in simple and practical manner without “water” and useless successful-success garbage

  • @aweklin
    @aweklin Рік тому +1

    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! ❤

  • @crazyfox55
    @crazyfox55 Рік тому +5

    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.

  • @lindermannla
    @lindermannla Рік тому +1

    Excelent tutorial! Thxnz Milan!

  • @KrzysztofBarbarski
    @KrzysztofBarbarski Рік тому +2

    Good to se little bit longer videos focused more on software architecture

  • @adamf6621
    @adamf6621 Рік тому +3

    nice video, will there be a video about event sourcing and saga patterns?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      - Saga: ua-cam.com/video/dlXCodLxhag/v-deo.html
      - Saga compensation: ua-cam.com/video/FPVzevl6Ri8/v-deo.html
      I'll do a video on ES sooner or later

  • @birgerg
    @birgerg Рік тому +4

    Will not using a shared class library with the contracts create a hard dependency between your services?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      You need a way to keep the services using the same contract. Later on, it can be distributed as a NuGet package.

    • @pilotboba
      @pilotboba Рік тому +2

      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.

    • @Oleks_
      @Oleks_ Рік тому

      @@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

    • @markcabana5864
      @markcabana5864 5 місяців тому +1

      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”

  • @gabrielzalisz
    @gabrielzalisz 8 місяців тому +1

    I smashed the like button. It still looks awesome after being smashed. Greetings from Czechia!

  • @f.donnet8165
    @f.donnet8165 Рік тому +2

    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 ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      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.

  • @JayMatlou
    @JayMatlou 6 місяців тому

    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.

  • @ahmedlutfiobeidat2142
    @ahmedlutfiobeidat2142 5 місяців тому

    Thank you Milan you are amazing

  • @iliqngorki3310
    @iliqngorki3310 Рік тому +1

    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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      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.

  • @mohsinazamafridi8566
    @mohsinazamafridi8566 Рік тому +1

    Great video,

  • @Alihndhwhrhdheh
    @Alihndhwhrhdheh Рік тому +3

    Please make video about saga and apigateway 😊

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      - Saga: ua-cam.com/video/dlXCodLxhag/v-deo.html
      - Saga compensation: ua-cam.com/video/FPVzevl6Ri8/v-deo.html
      - YARP load balancer (can easily be extended to API gateway): ua-cam.com/video/0RaH9hhOF4g/v-deo.html

  • @iPazooki
    @iPazooki Рік тому +1

    Thanks for your awesome video mate,
    It would be great if you create some videos about distributed tracing.

  • @rhexcasas8452
    @rhexcasas8452 Рік тому +1

    very nice. thank you.

  • @besikkristesiashvili
    @besikkristesiashvili Рік тому +2

    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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Basically you want every microservice to have its own database, holding the data required by that service

    • @besikkristesiashvili
      @besikkristesiashvili Рік тому

      @MilanJovanovicTech when data is relational? Is it normal to have a full copy of tables into different databases according to microservices?

  • @codemonk1999
    @codemonk1999 Рік тому +1

    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!

  • @gauravsingh-qt2zo
    @gauravsingh-qt2zo Рік тому +1

    Milan can you make video on implementing oauth 1.0 and 2.0?

  • @VytautasLL
    @VytautasLL Рік тому +3

    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?

    • @ArinSinabian
      @ArinSinabian Рік тому

      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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Service B stops while handling the event?

    • @ArinSinabian
      @ArinSinabian Рік тому

      @@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?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      @@ArinSinabian Yes, but I'm trying to clarify if that's what he meant

    • @2u1u
      @2u1u Рік тому

      I would assume the message sits on the queue until its handled

  • @HamzaKhan-ld5fj
    @HamzaKhan-ld5fj Рік тому +1

    Do i need to create complete docker-compose file or only the rabbitMq one?

  • @marshallkoo5294
    @marshallkoo5294 Рік тому +1

    Is it possible to run the program after finishing work to see the results?

  • @aditsheth1896
    @aditsheth1896 Рік тому

    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..?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      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

  • @АнатолийБобко-щ6и

    Hi, Milan! Awesome and useful video! Do you always use primitives such as Result, Error and etc. in your projects?

  • @habibulrehman9334
    @habibulrehman9334 9 місяців тому

    Great content

  • @HimabindhuBuska
    @HimabindhuBuska Рік тому +1

    Hi Milan, Where you added queue and exchanges configurations.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      MassTransit takes care of that behind the scenes

    • @HimabindhuBuska
      @HimabindhuBuska Рік тому

      @@MilanJovanovicTech can we handle multiple consumers using this mass transit?

  • @juliangzr4998
    @juliangzr4998 Рік тому +1

    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?

  • @peddapetavenkatesh3854
    @peddapetavenkatesh3854 7 місяців тому

    best structure and High perfomance

  • @lettuceturnipthebeets790
    @lettuceturnipthebeets790 Рік тому +1

    Milan, thank you for the awesome video!
    Could you share what VS extensions you use?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      I use ReSharper, Editor Guidelines, and Color Output for the build console highlighting

  • @LucasHenriquedeBrito
    @LucasHenriquedeBrito Рік тому +1

    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?

  • @mrcarlpaton
    @mrcarlpaton 8 місяців тому +1

    How do we ensure CreateArticle will save to the dbcontext AND the created event is published? Ie: make the operation atomic?

  • @RohanShakya
    @RohanShakya Рік тому +1

    Very informative video! How would we normally share 'Contracts' between two applications in a real world project?

  • @2u1u
    @2u1u Рік тому +1

    How would you keep microservices decoupled if microservice A needs data from microservice B without a direct call to eachother?

  • @kevinlloyd9507
    @kevinlloyd9507 Рік тому +1

    @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 :)

  • @antonmartyniuk
    @antonmartyniuk Рік тому +1

    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

  • @RMarjanovic
    @RMarjanovic Рік тому +1

    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?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      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.

  • @paikesitics
    @paikesitics 8 місяців тому

    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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      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.

    • @paikesitics
      @paikesitics 8 місяців тому

      @@MilanJovanovicTech Noted. Thanks!

  • @albertwaelti7561
    @albertwaelti7561 Місяць тому

    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
      @MilanJovanovicTech  Місяць тому

      Why is concurrency a problem here? (for different messages, for example) 🤔

    • @albertwaelti7561
      @albertwaelti7561 Місяць тому

      @@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.

  • @yuvrajgaikwad8972
    @yuvrajgaikwad8972 Рік тому +1

    Can you do comparison mass transit vs Rebus

  • @balajisairamnarasimhan
    @balajisairamnarasimhan Рік тому +1

    may I know why the publisher class always have to be static ?

  • @pabloguerracolombia
    @pabloguerracolombia Місяць тому

    Good content, question: Can MassTransit be used in a .net Minimal web api? Regards.

  • @yelshabasy
    @yelshabasy Рік тому +1

    Is this the same as domain events, a little confused on that

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      No, these would be integration events. Domain events are bound to a single domain. Integration events leave the boundary of a domain.

  • @emanuelcordovamontiel1017
    @emanuelcordovamontiel1017 8 місяців тому

    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

  • @tapqus
    @tapqus Рік тому

    Why at 18:30 you fetching Events collection from another query instead of join & select from navigation property?

  • @youssefelshabasy
    @youssefelshabasy Рік тому +1

    If you are experienced with it, could you make a video on how we can use the actor model in DDD

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I didn't work with the Actor model before, but I can make some introductory videos as I study the topic

  • @microtech2448
    @microtech2448 Рік тому +1

    That's straight to the point, that's good. What's your opinion on calling microservices through http clients?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      Perfectly acceptable integration pattern. I'll do a separate video discussing HTTP vs Messaging

    • @microtech2448
      @microtech2448 Рік тому

      Waiting for that 👍

  • @Kylefuller002
    @Kylefuller002 7 місяців тому

    Would this work between .net framework and .net 8? Could I use masstransit to communicate back and forth?

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 місяців тому

      In theory yes? It's just messages being sent over a message bus. But I can't say for sure.

  • @JuanCamba81
    @JuanCamba81 9 місяців тому

    Awesome!

  • @eziamakanv
    @eziamakanv Рік тому +3

    Great tutorial Milan! As a suggestion could you please cover how an API gateway could be implemented for this project? Maybe using Ocelot?

  • @Paul-uo9sv
    @Paul-uo9sv 2 місяці тому

    if we're using Aspire with RabbitMQ should we also use MassTransit with Aspire?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 місяці тому +1

      I think the question is "Should we use MassTransit with RabbitMQ"? 🤔

    • @Paul-uo9sv
      @Paul-uo9sv 2 місяці тому

      @@MilanJovanovicTech i think so. It's going to work dude

  • @techpc5453
    @techpc5453 Рік тому +2

  • @iyerpram
    @iyerpram Рік тому +1

    Can we replace masstransit with nservicebus

  • @abhishekjadhav9289
    @abhishekjadhav9289 Місяць тому

    Thank you for the nice video. How to find the host name of my rabbitmq ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Місяць тому

      localhost if exposes, in docker network use container name

  • @kitanddaniel
    @kitanddaniel 11 місяців тому

    Good information but you are not showing what is happening in RabbitMQ. For example: how many Queues were created? How to handle retries?

  • @pilotboba
    @pilotboba Рік тому +1

    Why don't you map the Article and ArticleEvents relationship in the Consumer/Reporting Project? It would simplify your query.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      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.

    • @pilotboba
      @pilotboba Рік тому

      @@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.

  • @NasirAli-yk9bp
    @NasirAli-yk9bp 7 місяців тому

    if you can please show how to implement synchronous communication with microservices 😋

  • @pramod.kulkarni9607
    @pramod.kulkarni9607 6 місяців тому

    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

  • @JimRohn-u8c
    @JimRohn-u8c Рік тому +2

    Do they have a UA-cam Channel like yours but for Java? 😭

  • @Maxim.Shiryaev
    @Maxim.Shiryaev Рік тому +4

    And now come failures... DB not vavailable, messages lost etc. With all that transactional outboxes, sagas and so on.

  • @sunzhang-d9v
    @sunzhang-d9v Рік тому +1

    The consumer reports an error, how to fix the system, how to re-execute

  • @hamitkarahan2973
    @hamitkarahan2973 Рік тому +1

    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.

  • @NavodWickra
    @NavodWickra 3 місяці тому

    MassTransit or ServiceStack?

  • @codenetw
    @codenetw 6 місяців тому

    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.