![]() I will probably switch to Azure Service Bus, but since I can’t run that locally I am using RabbitMq for development. The reason I’m don’t think I’ll use it in production is that I’m a solo developer with a small budget, so I want to keep infrastructure maintenance & cost to a minimum so cheap PAAS is my preference for everything. ![]() I don’t think I’ll use it in production.I’m not going to go into a lot of detail on RabbitMq for 2 reasons. I will talk about this a bit more later on in this post. This is also the area where you add your consumers. Finally, we set the ReceiveEndpoint, where we can set the retry policy and Prefetch count among other config items. After that, the host is configured with the URI and the user name & password needed to connect to it. Inside this, we add a bus where we tell it what type of bus it will be. The first part AddMassTransit does what it says and adds MassTransit to the builder. Host.Password(massTransitConfig) Ĭfg.ReceiveEndpoint(BusSettings.EventsService,Įp.UseMessageRetry(r => r.Interval(2, 100)) Var massTransitConfig = config.GetSection(BusSettings.MassTransitConfig) Var serviceBusHost = config.GetConnectionString(BusSettings.ServiceBusConnection) Var config = ConfigurationHelper.GetConfiguration() Protected override void Load(ContainerBuilder builder) The code for this looks like the following. Add MassTransit to the ContainerBuilder.Inside the module, there are 4 parts to configuring MassTransit. I configured the Bus in an AutoFac module. In the end, I configured the consumers in the Bus configuration. Although in the code sample there was a comment saying that they weren’t sure if this was possible. Again there was documentation that suggested that this would be possible, but when I tried it out there were errors in the code sample from the docs. You will notice that I have a commented-out ConsumerModule that I wanted to use to register consumers. This code registers Autofac as my DI container and then loads the contents of the BusModule which is where my Bus is configured. public void ConfigureContainer(ContainerBuilder builder)īuilder.RegisterModule(new AutofacModule()) This is documented pretty well in the AutoFac docs. This allows us to configure the bus when AutoFac is loaded, during the application startup. The 2nd change I made was to add ConfigureContainer to Startup.cs. But this seems to do some health checks on the bus and start the bus if it isn’t already running. I did a little digging through the source code, and I think I found a brief reference in the MassTransit docs, although it doesn’t explicitly mention this method. This is to add the MassTransit Hosted Services public void ConfigureServices(IServiceCollection services) I found the answer here on StackOverflow. At the time of writing, this wasn’t documented on the MassTransit page. There were 2 changes that I needed to make to my Startup.cs. It’s easy to swap out the module, I’ll talk more about this later.I went with configuring it in an Autofac module. ![]() Net Core, there are a few ways of configuring MassTransit. Net core setup guide but as usual, the answer was found on StackOverflow.įor. There was only one gotcha, that probably should be included in the. Looking back at it there isn’t a lot involved to configure a basic setup of MassTransit. The API will subscribe to this Event and listen for it before returning a synchronous result that includes the time that the process took. The Service will then take the command off the bus and consume it, before publishing an Event indicating that the Ping was consumed. We will set up a Ping Controller in the API that will dispatch a command to the service via MassTransit. The 1st will be an API, and the Second will be a Service for application logic, working with a DB or whatever you want it to do. There will be 2 services that will communicate together across the bus. ![]() I want to bring the information I needed to get it working together in one place. All the information to get MassTransit setup is out there but it is spread across the documentation, GitHub issues, StackOverflow and all the other usual places. My application already uses AutoFac as a DI container, that I will take advantage of in this post. In this post, I want to set up MassTransit with RabbitMq and.
0 Comments
Leave a Reply. |