In case the exception is thrown, MassTransit will create a Fault message and send it back to the requester. What does the request handler look like in MassTransit?įor the aforementioned message contracts, the request handler can look like this: The response will be sent back to the requester. The action method then uses the MassTransit request client to send a request to a consumer. That header is read into a scoped type ( Token) using an action filter as part of the API request. NET 5, ASP.NET This sample uses an HTTP header named Token to pass credentials to an API Controller. The masstransit.Autofac package makes it really easy and masstransit is awesome. You can add this to the container, or you can register it yourself using: This will then resolve your consumers from the container. How to use Autofac dependency injection in MassTransit?įirst, there is an AutofacConsumerFactory that will resolve your consumers from the container. To configure the request client, use the AddRequestClient method as shown below. To register a request client, MassTransit has registration methods to ensure request clients are properly registered. MassTransit includes a request client which encapsulates the request/response messaging pattern. How to register a request client in MassTransit? ![]() The following example also separates the readiness from the liveness health check. To configure health checks, which MassTransit will produce when using the MassTransitHostedService, add the health checks to the container and map the readiness and liveness endpoints. How to configure health checks in MassTransit? ![]() ![]() This is done where you add Masstransit to the pipeline in Startup.cs. When the Consumer is created it needs to be registered with MassTransit. Inside the Consumer, you will have the logic you want to perform when the command or event is received.
0 Comments
Leave a Reply. |