No video

Request Response Messaging Pattern with MassTransit

  Рет қаралды 14,733

Milan Jovanović

Milan Jovanović

Күн бұрын

☄️ 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
The definition of the Request Response pattern is: "It is a message exchange pattern in which a requestor sends a request message to a replier system, which receives and processes the request, ultimately returning a message in response." In this video, I'll show you how to implement asynchronous Request Response messaging with MassTransit and RabbitMQ.
Join my weekly .NET newsletter:
- www.milanjovanovic.tech
Read my Blog here:
- www.milanjovanovic.tech/blog
Chapters
0:00 What are we trying to implement?
1:15 Adding the Request Response message contracts
3:12 Sending the Request message with IRequestClient
4:45 Consuming the Request and returning the Response
9:05 Refactoring Request Response messaging to a service
11:39 Returning multiple Response message types

Пікірлер: 79
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@dcernach
@dcernach 10 ай бұрын
Great video! Please consider creating a series of videos about MassTransit, with a focus on topics like State Machines, Routing Slips, and more. MassTransit is a fantastic library to be used within microservices!
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
I already have a few about MassTransit, but I'll happily do more
@nove1398
@nove1398 10 ай бұрын
I would like to see these as well
@ferdikosasih
@ferdikosasih 8 ай бұрын
Hi have you ever compared with cap library? What the differences
@rezvlt9285
@rezvlt9285 9 ай бұрын
You always make the videos I most need. Thank you !
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
I have a hunch for that 😁
@michaelreiners8437
@michaelreiners8437 3 ай бұрын
Thanks a lot! Exactly what I just needed :)
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
You're welcome! :)
@GeoffSeeley
@GeoffSeeley 10 ай бұрын
You should probably handle timeouts for Requests as well because there is no guarantee you'll get a Response. This is one of the fun things about Event driven systems 🙂
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
The default timeout is 30s. If it takes more than that to get a response, you probably shouldn't be doing request-response anyway. But I agree that it should be handle in some way
@mohamedalaa8212
@mohamedalaa8212 10 ай бұрын
great video! How about making your next one on Circuit Breakers or Bulkhead pattern or more on MassTransit ? I'm sure it would be awesome
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Great ideas!
@KenzoArts
@KenzoArts 10 ай бұрын
Hello Milan, Would you please consider making a course about Microservices? I love so much your videos !
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
It will happen at some point :)
@PhobiaQQ
@PhobiaQQ 10 ай бұрын
great video, but I could not find this pattern described in MassTransit documentation. It's a pity you missed a part how you set up a message broker here. Did you use separate queue for request/response? Also I found that request/response is async pattern for http communication, while request/reply is async messaging pattern
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Here: masstransit.io/documentation/concepts/requests
@renatogomes3457
@renatogomes3457 10 ай бұрын
Hi Milan, awesome content as always! Is it a good practice to completely remove the use of MediatR and switch to Request/Response with MassTransit (InMemory, perhaps)? I'm a bit confused, but don't both serve the same purpose? Could you please provide some insights on this? Thank you very much.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Consider the ease of use with both libraries. MediatR is much simpler to configure and use than MassTransit. If all I need is an in-memory bus, MediatR is still a great choice
@pilotboba
@pilotboba 10 ай бұрын
imnsho Mediatr is for intraprocess messaging. Masstransit / Rebus are for interprocess messaging.
@guilhermebley4001
@guilhermebley4001 10 ай бұрын
Great video. One doubt, when we use AsNoTracking in EF, we need to call it at beggining or end of query?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
It won't matter.
@user-fj6js6px6f
@user-fj6js6px6f 10 ай бұрын
What is benefits of using RabbitMq instead of http is this case? It looks like synchronous way of communicating
@akashkarve1991
@akashkarve1991 10 ай бұрын
Http is synchronous, rabbit mq request-response is async
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
It looks like it's synchronous because the caller has to "block" and wait for a response. But the benefit is that the services don't have to know about each other - unlike with HTTP. You need to know which API to call and where to find it.
@musazulu7013
@musazulu7013 10 ай бұрын
Excellent video @MilanJonovicTech, is it possible to get a tutorial about Kafka
@PhatBoyG
@PhatBoyG 10 ай бұрын
I have an entire series on Kafka with MassTransit: kzbin.info/aero/PLx8uyNNs1ri0RJ3hqwcDze6yAkrmK1QI5
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Chris stealing the show 😁
@n.sharma5810
@n.sharma5810 29 күн бұрын
Hi Milan, if possible please create a small project explains microservice architecture completely
@MilanJovanovicTech
@MilanJovanovicTech 28 күн бұрын
A small project can't explain that
@muhammadtariq8323
@muhammadtariq8323 10 ай бұрын
I requested you that make a video on .NET Core, static file response compression. Pre-Compress (br / gzip) or run time by .NET Core or IIS. Which are best and how to implement
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Ok
@muhammadtariq8323
@muhammadtariq8323 10 ай бұрын
@@MilanJovanovicTech thanks 👍
@thedacian123
@thedacian123 3 ай бұрын
How did you registered in the DI container IRequestClient?
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
You don't have to, it's automatically registered
@user-xm7sh3vw8o
@user-xm7sh3vw8o 10 ай бұрын
MassTransit+RabbitMq ,The consumer fails and can be put into the standby queue. What needs to be done?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Handle the error on the request client side
@nomad191
@nomad191 10 ай бұрын
Great Video. Where can I download the source code for this?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Hi, I share the source code on Patreon
@coderider3022
@coderider3022 9 ай бұрын
How does it correlate response properly , doesn’t seem to enable sessions on a queue?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Attaches a message ID
@giorgigiorgobiani9547
@giorgigiorgobiani9547 4 ай бұрын
Hello Milan, i use this request/response pattern with rabbitMQ, but sometimes i have an issue: when api B is in idle state (not recieving requests) rabbitMQ connection of api B is lost and when i send reqeust from api A with requestClinet i get timeoutexception. is there some method to overcome this issue?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Nope. That's called temporal coupling. In request-response we assume the other side is always available. But that might not always be the case.
@giorgigiorgobiani9547
@giorgigiorgobiani9547 4 ай бұрын
@@MilanJovanovicTech ok but is there a way keep other side always available..to configure rabbitMQ connection to be all the time alive while api running..do u know such thing? If not, what is solution ..
@balajisairamnarasimhan
@balajisairamnarasimhan 10 ай бұрын
Can we use mass transit if we are making this cloud native microservices ? Benefit of using mass transit ?
@jeroen7362
@jeroen7362 10 ай бұрын
the benefit of MT is that you are decoupled from the transport/bustype. so locally you can run rabbit, or even rabbit in a docker. and in the cloud you use azure servicebus or other cloud bus. in unittest you can run in memory bus. your code is transport agnostic, only in the startup of the bus you need to start one bustype depending on an appsetting.
@balajisairamnarasimhan
@balajisairamnarasimhan 10 ай бұрын
@@jeroen7362 thanks a lot
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
You absolutely can
@balajisairamnarasimhan
@balajisairamnarasimhan 10 ай бұрын
@@MilanJovanovicTech thanks Milan so can you guide me the steps for that ? Or does it work internally as a container ?
@makemeafirewall
@makemeafirewall 10 ай бұрын
The reason you said you register the ArticleViewsService as scoped is because IRequestClient is also scoped, how is it possible to generally check by DI container and the dependency chain to make sure I don't do anything funny in the registration I wasn't supposed to do? Is there a tool to see all the DI chain or the places where things are not using the same registration type?
@jeroen7362
@jeroen7362 10 ай бұрын
if you use the built in DI you will find out for sure without tools, when a singleton tries to use a scoped service. the other way around is perfectly fine. You can use scoped services in a singleton by creating a scope around it.
@makemeafirewall
@makemeafirewall 10 ай бұрын
@@jeroen7362 what happens when a singleton tried to use a scoped service without creating a scope? Do I get an error? Always?
@makemeafirewall
@makemeafirewall 10 ай бұрын
@@jeroen7362 we had an issue with the DB context that was used by a singleton and we changed it to be transient to solve the problem, don't exactly remember. I wanted a tool that shows me the dependency tree to find these errors if I suspect I did something wrong with the service registration.
@jeroen7362
@jeroen7362 10 ай бұрын
@@makemeafirewall as far as i have experienced it will always throw a runtime exception like "Cannot consume scoped service from singleton" This would usually only happen during development if you even touch the appservice in your debug session.
@makemeafirewall
@makemeafirewall 10 ай бұрын
@@jeroen7362 i think it gets more complicated when a transient is injected with a scoped or the other way around. There should be a way to get the tree and search it, also it would be great to see the request pipeline because sometimes the project is already running in production and you are not always aware of the order of things, especially handlers that are used or even registered using reflection
@GamalSherbiny
@GamalSherbiny 7 сағат бұрын
what advantage does this solution have over http request response?
@MilanJovanovicTech
@MilanJovanovicTech 6 сағат бұрын
You don't need to know the address of the other service - only the message contract. This can be a big advantage. The downside is increased latency, as we're passing around more messages.
@hanoguzakpinar
@hanoguzakpinar 7 ай бұрын
is there any way to use exchange names for publisher?
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
MassTransit routes this to an exchange under the hood. I'm sure it's possible to configure it explicitly, but you should check the docs.
@raghavendrahabbu
@raghavendrahabbu 2 ай бұрын
Where can I get complete source code?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Patreon: www.patreon.com/milanjovanovic
@BlueLabel1980
@BlueLabel1980 5 ай бұрын
Github for this expample?
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
I share the source code on Patreon
@amitkumdixit
@amitkumdixit 10 ай бұрын
Don't see any added benefit in this use case. One more failure point in the response cycle.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Anything can fail in distributed systems, I don't see that as a counter point
@DjDanny32
@DjDanny32 10 ай бұрын
MassTransit + RabbitMQ adds many benefits. For example, imagine your dB is down. Rabbit will retry your request (within your defined parameters) for you
@techpc5453
@techpc5453 10 ай бұрын
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
👋
@srik790
@srik790 10 ай бұрын
But I guess the UI composition technique is better in this scenario.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Perhaps
@srik790
@srik790 10 ай бұрын
@@MilanJovanovicTech Any plans to cover UI composition in your videos?
@haraheiquedossantos4283
@haraheiquedossantos4283 3 ай бұрын
By the way I agree with the comment below, like using some BFF to orchestrate. And I think messaging Request-Response pattern is better suited to workflows long running business process that span multiple boundaries when we are dealing with sagas. Don't you agree?
The Brand New Way to do Fault Handling in Polly V8
16:09
Milan Jovanović
Рет қаралды 17 М.
How to Edit Photos on CapCut | CapCut 101 | CapCut
6:53
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 33 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 41 МЛН
Joker, what is this doing?!#joker #shorts
00:31
Untitled Joker
Рет қаралды 9 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 5 МЛН
Voided Trickster
13:07
CaptainLance9
Рет қаралды 6 М.
Build Clean Messaging in .NET with MassTransit
21:44
Nick Chapsas
Рет қаралды 96 М.
Getting Started With MassTransit (Beginner Friendly)
12:35
Milan Jovanović
Рет қаралды 18 М.
This Is What MassTransit Does to Your Message Broker | RabbitMQ
14:21
Milan Jovanović
Рет қаралды 9 М.
How to Structure a Modular Monolith Project in .NET
15:57
Milan Jovanović
Рет қаралды 34 М.
The Best Way To Use Docker For Integration Testing In .NET
19:34
Milan Jovanović
Рет қаралды 32 М.
Structured Logging Using Serilog and Seq in .NET
13:16
Milan Jovanović
Рет қаралды 24 М.
Creating a State Machine Saga With MassTransit (Orchestrated Saga)
15:41
Milan Jovanović
Рет қаралды 10 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 33 МЛН