What Is A Message Queue + RabbitMQ and MassTransit Integration

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • ☄️ Master the Modular Monolith Architecture: bit.ly/3SXlzSt
    📌 Accelerate your Clean Architecture skills: bit.ly/3PupkOJ
    🚀 Support me on Patreon to access the source code: / milanjovanovic
    Message queues are required in most modern systems for the great benefits they bring. They're very useful for designing decoupled communication between components by passing messages to the queue. In this video, I'll show you how to use a message queue with MassTransit and connect it to RabbitMQ to publish messages.
    Join my weekly .NET newsletter:
    www.milanjovanovic.tech
    Read my Blog here:
    www.milanjovanovic.tech/blog
    Subscribe for more:
    / @milanjovanovictech
    Chapters
    0:00 Running RabbitMQ in Docker
    0:46 Configuring message broker settings
    2:12 MassTransit configuration
    4:30 Why is a message queue useful?
    5:40 Publishing messages to the queue
    8:21 Implementing EventBus with MassTransit
    10:46 Consuming messages from the queue
  • Věda a technologie

Komentáře • 119

  • @MilanJovanovicTech
    @MilanJovanovicTech  Před rokem +4

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

    • @fieryscorpion
      @fieryscorpion Před rokem +1

      Great video. Do you have a blog post for this video? Couldn't find it. (I like reading instead of watching videos 😊)

    • @kristiyanivanov7414
      @kristiyanivanov7414 Před rokem

      joined it, thanks for putting all that content out there! amazing stuff

  • @PhatBoyG
    @PhatBoyG Před rokem +28

    Great video, glad you're having fun exploring MassTransit!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +5

      I'm humbled, Chris! I've been using MassTransit on an internal project for the past 2 years, and I love it. Planning to make a lot more content around what it can do :)

    • @fieryscorpion
      @fieryscorpion Před rokem +6

      The creator of MassTransit 🚌 himself!

  • @majormartintibor
    @majormartintibor Před rokem +23

    Very good video, but I think Mass Transit + RabbitMQ would deserve and need more content. I hope you will do some follow up videos for this. Show the difference between Orchestration and Choreography. Maybe do a seperate little project and debug through 3-4 microservices involved in a transaction etc.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +5

      For sure, I have a lot more content planned around distributed systems!

    • @davittonoyan6537
      @davittonoyan6537 Před rokem

      ​@@MilanJovanovicTech Looking forward for that))

  • @velkumars26
    @velkumars26 Před rokem +1

    @Milan awesome video on RabbitMQ.
    Looking forward to see more video on this playlist like Mediator to RabbitMQ, Mass Transit - Publish vs. Send, Commands etc.

  • @mylesdavies9476
    @mylesdavies9476 Před rokem +3

    Impeccable timing, I'm just trying to get started with rabbitmq 🙂

  • @kjbetz
    @kjbetz Před rokem +1

    Milan, great video as always!

  • @DoSoft-t8p
    @DoSoft-t8p Před 22 dny +1

    Great video, I Learn a lot from u thank u

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 21 dnem

      Sure thing! Check this one also for the internals: czcams.com/video/zKppEQIzvcU/video.html

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat

    Great as always

  • @kodindoyannick5328
    @kodindoyannick5328 Před 5 měsíci +1

    It's very interesting video. Thank you a lot for all.

  • @mahmoudalaskalany
    @mahmoudalaskalany Před rokem +1

    Great One Milan as usual
    I was searching for a related video on the channel to comment about new video idea
    It is about how to create a consumer and producer console template so that when i need new consumer or producer i just go and create a new project of that template 😅

  • @allenbythesea
    @allenbythesea Před rokem +4

    Good video and useful to explain the subject matter. I used to agree but honestly if you want to go at scale you need to move to the 2.0 (ish) of queue tech which are the cloud native queues (rabbit types) and logs (think kafka) in gcp, azure and aws. These systems provide much deeper serverless options that can scale up with little hassle. (chief arch, fortune 5)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +3

      Good thing that with MassTransit, the messaging is abstracted. You can easily plug in Azure Service Bus. I used AWS Rabbit MQ for example.

    • @danielegiovanetti9258
      @danielegiovanetti9258 Před rokem

      @@MilanJovanovicTech you mean that this example code run perfectly in an Azure bus? Could be good to see a video where you explain the connection with Azure bus. Thanks so much for explaining this topic.

  • @nove1398
    @nove1398 Před rokem +1

    I usually add event to the object name as well, it helps me to show explicit intent modeling IMO

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      Exactly, for the same reason I also append Command/Query to class names

  • @chudo81
    @chudo81 Před rokem +1

    Great video. But its more interesting to see how to interact with non-.net consumers. Who do not know anything about masstransit and its envelope and other things.

  • @estebanhugosomma3012
    @estebanhugosomma3012 Před rokem +3

    Excellent video Milan as always! I just started to learn MassTransit this week and I was need one of your videos about MassTransit, so you read my mind!
    2 questions: Can you share the source code of the video? And, MassTransit have a Mediator pattern implementation, can we replace the MediatR library for MassTransit Mediator? Greetings from Argentina!!!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      Send me an email for the source code :)
      I haven't used MassTransit's Mediator, to be honest, so I can't really comment on it.

  • @user-pq9yh
    @user-pq9yh Před rokem +4

    Pressed like before actually watching the video.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +2

      I appreciate the love 😊
      Let me know what you thought of the video.

    • @user-pq9yh
      @user-pq9yh Před rokem +1

      @@MilanJovanovicTech It was great. Thank you for sharing your knowledge

  • @pureevil379
    @pureevil379 Před rokem +1

    Great video!
    So RabbitMQ is the lightweight database/queue persisting the events.
    You hook up Mass Transit to connect to this 'queue' and whenever an event is persisted to the queue the appropriate mass transit event handler will consume it.
    Is this an alternative to the transactional outbox pattern where you raise events to the DB and process them with a background service? They are similar. I can see the benefit of both for sure.
    This one feels more lightweight than the TransactionalOutbox -> Background Service reading jobs. But maybe that's because I am considering that with the raising of domain events and the aggregate root unit of work commits to db.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      You can think of a queue as a pipe. Something comes in on one end, and comes out on the other end.
      It's different from an outbox since it's another external system to your database. It increases the surface area for things to fail.
      I'm planning another video soon about Sagas and it'll cover queues a little bit more

  • @salmanzafar-jr1iu
    @salmanzafar-jr1iu Před rokem +1

    Thanks for another great video.
    should it not be extending your CLEAN architecture video where the Outbox pattern was used to persist events in the database and Quartz/Hangfire as background service using MassTransit to push those events from the database to Queuing service?

  • @user-gg9oe1tz5u
    @user-gg9oe1tz5u Před rokem +1

    Great video, but could you explain how you've set up your project to run in a docker container. Apologies if I've missed a video where you explained this.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      I don't think I covered a Docker-compose set up from scratch. Will make a video abut that!

  • @nl6049
    @nl6049 Před rokem +1

    Really nice explanation/demo. I recommend you to upgrade your mic and then you'll sounds like a real pro content creator. Knowledge wise, seems like you already got what it takes :)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      Oh, really. You think the mic doesn't cut it? 🤔

    • @nl6049
      @nl6049 Před rokem +2

      @@MilanJovanovicTech the content is great, maybe I just grew accustomed to Jeffery Way voice

  • @davittonoyan6537
    @davittonoyan6537 Před rokem +1

    Thank you, I have one question. When you publish the message how the RabbitMq stores the data? I mean does it make some kind of serialization ( json, byte array) ?

  • @raghavendrahabbu
    @raghavendrahabbu Před 2 měsíci

    All your videos are great. Can you share the code that you are using in your videos.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 2 měsíci

      Yes, here: www.patreon.com/milanjovanovic
      And on some of them, check the pinned comment in case the source code is public :)

  • @TheKsenija123
    @TheKsenija123 Před rokem +1

    Hi Milan! Can I ask you something? When you use records in C# is it much simple and less code with only the constructor and pass the values through the constructor instead of properties? or this is just a clean-written code? After all, records are read-only I know. Maybe I'm wrong. Can't be modified additionally in another place with accessing some property. Thanks for the videos 🙂. Поздрав од Македонија. 😉

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +2

      I find it simpler, that's why. Plus I get immutability, etc. By no means a convention, but an approach I found useful. MassTransit also recommends using interfaces for message contracts. But this is annoying in that you'll have to make implementations on sending side, so double code. Pozdrav iz Niša :)

    • @TheKsenija123
      @TheKsenija123 Před 11 měsíci

      @@MilanJovanovicTech Thanks a lot for answering me 🙂

  • @kostasgkoutis8534
    @kostasgkoutis8534 Před rokem +1

    What is the level of support for Mass Transit for the Outbox pattern? Is this going to be presented later or we rely on the video already shared in the Clean Architecture series?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +2

      I haven't explored it, honestly! I'm sure there's good support however, but I'll do some research and make a video.

    • @kostasgkoutis8534
      @kostasgkoutis8534 Před rokem

      I checked it quickly in the docs they do have something cooked up, I would love to see this in a video :))

  • @_JustBeingCasual
    @_JustBeingCasual Před rokem +1

    Is this a good replacement for outbox pattern? Still experimenting and all those patterns are a tiny bit hard to swallow without practical experience.
    Thanks for the great video

  • @nick066hu
    @nick066hu Před 11 měsíci +1

    Is OK to connect to the Message Queue / RabbitMQ from a client running javascript? Or would it be a design failure, an overkill, (too much load/ package size, etc.) and should translate to REST apis / websocket instead for the small clients?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 11 měsíci

      Isn't that a security concern? 🤔

    • @nick066hu
      @nick066hu Před 11 měsíci

      @@MilanJovanovicTech That's is also why I am asking, There most be reasons it is not a widespread way of doing it.
      I don't know , but you're right, I think, to protect the REST APIs + Websocket / SignalR, etc. with TLS + token auth, etc is much simpler and usual then to have the equivalent with MQTT messages on the client I don't know if such a solution exists at all.
      However on even smaller client, like a microcontroller, a direct MQTT still make sense.

  • @vanasisbaboomi7819
    @vanasisbaboomi7819 Před rokem +1

    Great Video, but one question.
    what is difference between event bus and domain event from previous videos?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      One is in-memory, one is a separate process

    • @vanasisbaboomi7819
      @vanasisbaboomi7819 Před rokem

      ​@@MilanJovanovicTech can we implement domain event with event bus? Can you tell a little more. Thanks

  • @iamnoob7593
    @iamnoob7593 Před rokem +1

    Hi , pls would request you to make more detailed videos involving 2 microservice + az function using Mass Transit + RabbitMq.

  • @David-rz4vc
    @David-rz4vc Před 11 měsíci +1

    What exchange is mass transit using? Topic? Fanout? Direct? I'm assuming it setups these with the bindings to the queue as well.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 11 měsíci +1

      It's different based on the underlying transport, so for RabbitMQ these are the docs: masstransit.io/documentation/transports/rabbitmq

  • @winstochurgle9133
    @winstochurgle9133 Před 6 měsíci +1

    I put a breakpoint inside of Consume() method but apparently I can't get there. I registered my Consumer inside of MassTransit configurator. I notice activity in RabbitMQ, but the consumer method isn't executed.
    Why?🤔
    I just recently started learning RabbitMQ. Shouldn't I have a queue created in this case?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 6 měsíci +1

      Probably missing a call to ConfigureEndpoints inside the call the UsingRabbitMq (I forgot to mention that in the video, my bad)

    • @winstochurgle9133
      @winstochurgle9133 Před 6 měsíci

      @@MilanJovanovicTech You're right, I added it and now it's ok. Thanks for feedback

  • @bayobizzle
    @bayobizzle Před rokem +1

    What's the reason for abstracting the IPublishEndpoint behind another interface IEventBus?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      You may want to introduce some logic around the publish action, and making an abstraction for that is a good idea. But you absolutely don't need to do it, and can use IPublishEndpoint directly

  • @oleksiibubenko4905
    @oleksiibubenko4905 Před 4 měsíci +1

    I don't quite understand why the extra abstraction in the way of the EventBus class

  • @kimberlyjacobsen4148
    @kimberlyjacobsen4148 Před 8 měsíci +1

    Great Video
    I just Noticed that with Core 6 and MassTransit 8.1.2
    you need to add rabbitMqConfigurator.ReceiveEndpoint In the Configuration for UsingRabbitMq in the Bus configurator Or am i missing somthing ?

    • @kimberlyjacobsen4148
      @kimberlyjacobsen4148 Před 8 měsíci

      just for Reference
      busConfigurator.UsingRabbitMq((context, rabbitMqConfigurator) =>
      {
      var messageBrokerSettings = context.GetRequiredService();
      rabbitMqConfigurator.Host(new Uri(messageBrokerSettings.Host),
      h =>
      {
      h.Username(messageBrokerSettings.Username);
      h.Password(messageBrokerSettings.Password);
      });
      rabbitMqConfigurator.ReceiveEndpoint("EndpointListenerName", endpointConfigurator =>
      {
      endpointConfigurator.ConfigureConsumer(context);
      });
      });

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 8 měsíci

      Yeah, must've omitted that part

  • @salehdanbous6783
    @salehdanbous6783 Před rokem +1

    Great, why not fire the Publish method inside a background job using Quartz or Hangfire like you did in TransactionalOutbox video?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      Didn't want to complicate it for an intro video, but that's a viable option. And what I generally do in production

    • @salehdanbous6783
      @salehdanbous6783 Před rokem

      @@MilanJovanovicTech Got it. Hope to see more videos on this subject ..

  • @jacobjacob8062
    @jacobjacob8062 Před rokem +1

    What exchange and queue this message was published? Because I can't see any configuration for exchange or queue

    • @mylesdavies9476
      @mylesdavies9476 Před rokem

      Good question, I guess the library provides some default values?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      MassTransit creates the required queues/topics for you in the background. It's abstracted away because it can vary depending on the actual message transport you're using.

    • @jacobjacob8062
      @jacobjacob8062 Před rokem

      @@MilanJovanovicTech OK and where is configuration for message transport? Because I see just publish message by default

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      @@jacobjacob8062 At thr beginning, the call to UsingRabbitMq

    • @jacobjacob8062
      @jacobjacob8062 Před rokem

      @@MilanJovanovicTech there is only configuration for host... But what about message transport?

  • @anilkarasahh
    @anilkarasahh Před rokem +1

    I am new to the Message Queue World, I am trying to learn about it and this video helped me a lot with that.
    I have implemented everything as you did. Though, in the RabbitMQ management page, the exchange does not show any consumers and the messages just disappear on their own. No logs, no emails, no hitting breakpoints, nothing. What may cause this?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +2

      I think you're missing some configuration code. Best refer to the MassTransit docs

    • @anilkarasahh
      @anilkarasahh Před rokem +1

      ​@@MilanJovanovicTech Yeah, I have missed something. Apparently, at the very end of the lambda function of UsingRabbitMq, there should be a "configurator.ConfigureEndpoints(context);" which I was missing. It solved the problem!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      @@anilkarasahh I believe I also missed it in the video, which added to the confusion :/

    • @anilkarasahh
      @anilkarasahh Před rokem

      @@MilanJovanovicTech It sometimes feels magical that something seems to be working on a tutorial and does not on me because something is missing. Never understood why and how :)

    •  Před rokem

      Milan forgot to configure the endpoints in the video on UsingRabbitMq. serviceBusBusFactoryConfigurator.ConfigureEndpoints(busRegistrationContext);

  • @JZO001
    @JZO001 Před rokem +1

    Hi, is there a Github source for this demo solution?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      No, I share the code on my Patreon: www.patreon.com/milanjovanovic

  • @shate74662000
    @shate74662000 Před rokem +1

    Can you make a video for Masstransit saga?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      I just recorded one for Rebus Saga, but the concepts will be similar to MassTransit

    • @shate74662000
      @shate74662000 Před rokem

      @@MilanJovanovicTech can't wait to watch

  •  Před 5 měsíci

    Why register the IEventBus as Transient and not as Scope?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 5 měsíci +1

      No particular reason. The IPublishEndpoint is scoped, so scoped would've been more correct there.

  • @nove1398
    @nove1398 Před rokem

    Question, would it be wise to implement multiple IConsumer of different types to the same concrete class? Assuming the events it consumes are related?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +1

      Good question! In theory that should work without a problem. On the other hand, I never tried it out so I have no idea how if it will work.

  • @xxXAsuraXxx
    @xxXAsuraXxx Před 11 měsíci +1

    Rabbitmq is good, but Kafka scales better I think

  • @kavkavy
    @kavkavy Před rokem +2

    do you guys memorize the code or what... i have never seen him using documentation in any video! so he memorize the syntax before or he opens the doc in the second screen i don't get it... and he never shares the original links. Please guys go and read the documentation you'll never learn like this

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem +6

      Or he simply worked with the library for a long time that he knows the code by heart? 😅
      That's how I make most of my videos to be honest, I talk about what I know.
      And of course I do my research beforehand, to brush up my memory. But you can't expect me to teach you everything in a 10-20min video. My vision is more to explore a concept and give you some direction, and it's up to you to go and do your own research.

  • @YasSin
    @YasSin Před 6 měsíci

    I have a shirt like your one 😂. It is clone 😂

  • @june3878
    @june3878 Před rokem +1

    Everything is cool, thanks! But! It's all in the sandbox category. What if we have a producer that is an external service (not in the same namespace as the consumer), and we need to beat off messages that accidentally entered our consumer in such a way as to not crash the application. To make everything beautiful and asynchronous. Here you would show such a complex example. how great it would be! but these are all "Hello, World!" The examples don't really help, to be honest. All those examples from the documentation are too primitive and have nothing to do with the combat environment. Thank you.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před rokem

      That's a pretty fair critique, to be honest. Now that I'm doing this full-time, I actually have the time to start working on some "real world" use cases for the videos

    • @june3878
      @june3878 Před rokem

      @@MilanJovanovicTech This is not criticism, this is a cry from the heart)) I have just such a task, I am intensively looking for combat options for Rabbitmq, and, alas, I can’t find it)) SOS))