How To Build Loosely Coupled Microservices With MassTransit

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 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 7 วันที่ผ่านมา

      Milan is great.

  • @vallJune
    @vallJune วันที่ผ่านมา +1

    Milan is my favorite knowledge transfer guy 🥰

  • @kinggrizzly13
    @kinggrizzly13 ปีที่แล้ว +10

    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

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

  • @gretings
    @gretings 5 หลายเดือนก่อน +1

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

  • @sauravbhatta5303
    @sauravbhatta5303 ปีที่แล้ว +4

    Great library

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

  • @kodindoyannick5328
    @kodindoyannick5328 9 หลายเดือนก่อน +1

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

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

  • @ryoman76
    @ryoman76 ปีที่แล้ว +16

    Great! For next video Masstransit Saga ?

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

  • @gabrielzalisz
    @gabrielzalisz 8 หลายเดือนก่อน +1

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

  • @AkashKarve-t2o
    @AkashKarve-t2o 9 หลายเดือนก่อน +1

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +2

      Infrastructure

    • @AkashKarve-t2o
      @AkashKarve-t2o 9 หลายเดือนก่อน

      @@MilanJovanovicTech could you make video for it

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

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

  • @lindermannla
    @lindermannla ปีที่แล้ว +1

    Excelent tutorial! Thxnz Milan!

  • @adamf6621
    @adamf6621 ปีที่แล้ว +3

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      - 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

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

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

  • @mohsinazamafridi8566
    @mohsinazamafridi8566 ปีที่แล้ว +1

    Great video,

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

  • @KrzysztofBarbarski
    @KrzysztofBarbarski ปีที่แล้ว +2

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

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

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

  • @HamzaKhan-ld5fj
    @HamzaKhan-ld5fj ปีที่แล้ว +1

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

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

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

  • @iPazooki
    @iPazooki ปีที่แล้ว +1

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

  • @habibulrehman9334
    @habibulrehman9334 9 หลายเดือนก่อน

    Great content

  • @rhexcasas8452
    @rhexcasas8452 ปีที่แล้ว +1

    very nice. thank you.

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

  • @marshallkoo5294
    @marshallkoo5294 ปีที่แล้ว +1

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

  • @RohanShakya
    @RohanShakya ปีที่แล้ว +1

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

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

  • @peddapetavenkatesh3854
    @peddapetavenkatesh3854 7 หลายเดือนก่อน

    best structure and High perfomance

  • @gauravsingh-qt2zo
    @gauravsingh-qt2zo ปีที่แล้ว +1

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

  • @АнатолийБобко-щ6и
    @АнатолийБобко-щ6и ปีที่แล้ว +1

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

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

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

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

  • @tapqus
    @tapqus ปีที่แล้ว

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Because I'm not using a navigation property 🤷‍♂️

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

  • @balajisairamnarasimhan
    @balajisairamnarasimhan ปีที่แล้ว +1

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

  • @Alihndhwhrhdheh
    @Alihndhwhrhdheh ปีที่แล้ว +3

    Please make video about saga and apigateway 😊

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      - 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

  • @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 26 วันที่ผ่านมา

    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  26 วันที่ผ่านมา

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

    • @albertwaelti7561
      @albertwaelti7561 26 วันที่ผ่านมา

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

  • @2u1u
    @2u1u ปีที่แล้ว +1

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

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

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

  • @emanuelcordovamontiel1017
    @emanuelcordovamontiel1017 7 หลายเดือนก่อน

    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
      @MilanJovanovicTech  7 หลายเดือนก่อน

      What do you mean by this? Select types of messages?

  • @yuvrajgaikwad8972
    @yuvrajgaikwad8972 ปีที่แล้ว +1

    Can you do comparison mass transit vs Rebus

  • @Kylefuller002
    @Kylefuller002 6 หลายเดือนก่อน

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

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

  • @kitanddaniel
    @kitanddaniel 10 หลายเดือนก่อน

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

  • @JuanCamba81
    @JuanCamba81 8 หลายเดือนก่อน

    Awesome!

  • @Paul-uo9sv
    @Paul-uo9sv หลายเดือนก่อน

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  หลายเดือนก่อน +1

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

    • @Paul-uo9sv
      @Paul-uo9sv หลายเดือนก่อน

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

  • @iyerpram
    @iyerpram ปีที่แล้ว +1

    Can we replace masstransit with nservicebus

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

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

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

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

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Yes, check here: masstransit.io/documentation/transports

  • @JimRohn-u8c
    @JimRohn-u8c ปีที่แล้ว +2

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

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

  • @NasirAli-yk9bp
    @NasirAli-yk9bp 6 หลายเดือนก่อน

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

  • @sunzhang-d9v
    @sunzhang-d9v ปีที่แล้ว +1

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Retries, dead-lettering are some of the things you can do

    • @sunzhang-d9v
      @sunzhang-d9v ปีที่แล้ว

      @@MilanJovanovicTech

  • @Maxim.Shiryaev
    @Maxim.Shiryaev ปีที่แล้ว +4

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

  • @NavodWickra
    @NavodWickra 3 หลายเดือนก่อน

    MassTransit or ServiceStack?

  • @techpc5453
    @techpc5453 ปีที่แล้ว +2

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 หลายเดือนก่อน +1

      Better build it all yourself 🤷‍♂️