: Bus is about to start with address rabbitmq://localhost:5672/accounting/-4g7yyyg5o96d6puubdj658n3ra?durable=false&autodelete=true&prefetch=8 : Bus has been created with address rabbitmq://localhost:5672/accounting/-4g7yyyg5o96d6puubdj658n3ra?durable=false&autodelete=true&prefetch=8 There should be messages similar to the following after a successful bus start-up: We can additionally put a Console.ReadKey after the code that stops the bus so that we can see the messages related to stopping the bus:įor the demo it is enough to start the receiver, we don’t need to send messages here. I’ve commented out all other observers we created in the previous post to easily identify the messages from the bus observer. IRabbitMqHost rabbitMqHost = rabbit.Host(new Uri("rabbitmq://localhost:5672/accounting"), settings => IBusControl rabbitBusControl = (rabbit => The RunMassTransitReceiverWithRabbit method in Program.cs of MassTransit.Receiver where we start and stop the bus can be extended with an extra line of code: We can register the bus observer within the block where we create the IBusControl object. The IBus object offers most bus-related methods and functions we used for our IBusControl object such as Send, Publish, ConnectConsumer etc., so there’s nothing stopping us from sending an extra message to a queue from within the bus observer. The method names reveal that we can monitor events related to creating, starting and stopping the bus. Public async Task StopFaulted(IBus bus, Exception exception)Ĭonsole.WriteLine(string.Concat(_logger, ": Bus exception at shut-down: ", exception.Message Public async Task StartFaulted(IBus bus, Exception exception)Ĭonsole.WriteLine(string.Concat(_logger, ": Bus exception at start-up: ", exception.Message Public async Task PostStart(IBus bus, Task busReady)Ĭonsole.WriteLine(string.Concat(_logger, ": Bus has been started with address ", bus.Address)) Ĭonsole.WriteLine(string.Concat(_logger, ": Bus has been stopped with address ", bus.Address)) Ĭonsole.WriteLine(string.Concat(_logger, ": Bus is about to start with address ", bus.Address)) Ĭonsole.WriteLine(string.Concat(_logger, ": Bus is about to stop with address ", bus.Address)) Public async Task CreateFaulted(Exception exception)Ĭonsole.WriteLine(string.Concat(_logger, ": Bus exception: ", exception.Message)) Ĭonsole.WriteLine(string.Concat(_logger, ": Bus has been created with address ", bus.Address)) The following BusObserver class in the MassTransit.Receiver project of the demo application shows a minimal implementation: All methods return a Task so they are prepared for the async-await paradigm. The IBusObserver interface is similar to the ones we saw in the previous post in that it has a couple of events that are triggered at various stages of the bus life cycle. In this post we’ll see how to register events that happen in the bus. The implemented interfaces need to be registered with the bus so that we can do any extra work on the messages such as logging or debugging. We cannot modify the message content so they are read-only operations. We can intercept messages using various observer interfaces when sending, publishing, receiving and consuming messages. In the previous post we learned how to intercept messages in MassTransit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |