AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Nservicebus vs masstransit4/11/2023 ![]() EnableInstallers line, add the following code:ĮndpointConfiguration.SendFailedMessagesTo("error") Let's add a retry policy to our Receiver endpoint: The best way to describe how they work is to see them in action. There are two types of retry policy: immediate retries and delayed retries. When a message handler fails, messages are automatically retried based on a pre-defined policy. ![]() NServiceBus has robust recoverability features for handling failures. It's inevitable that code will fail and it can do so for various reasons, such as network failures, database locks, changes in a third-party API, and plain old coding errors. Resilience in actionĮrrors are a fact of life in software systems. Now that you have everything working, let's break it. The Receiver displays the details of each Ping message it receives and the Sender logs the details of each Pong message it receives in reply. In the Sender, notice that a Ping message is dispatched every second, thanks to the SenderWorker background job. Our PingHandler is straightforward: when a Ping message is received, log the message details and reply back to the sender with a new Pong message. The Handle method takes the message itself as a parameter, and an IMessageHandlerContext, which allows further messaging operations, such as replying, sending commands, or publishing events. This interface tells NServiceBus that when the endpoint receives a message of type Ping, it should be processed by the Handle method in this handler. The class implements IHandleMessages, which defines one method: Handle. Let's ignore the commented code for now we'll get back to it later when we talk about recovering from failure. The other message class in the Shared projects is Pong.cs: public class Pong : NServiceBus.IMessage This message is a signal to the reader and to NServiceBus that it's a command, although there are other ways to identify messages without using interfaces. It's a simple C# class that implements NServiceBus.ICommand, an interface from the NServiceBus package. The Ping class defines a message that the Sender sends to the Receiver. The interfaces aren't required, but they give us some extra validation from NServiceBus and allow the code to be self-documenting.įirst we'll review the Ping.cs class public class Ping : NServiceBus.ICommand It includes a reference to the NServiceBus NuGet package, which contains interfaces you can use to identify our messages. The Shared class library is where you define the contracts used to send our messages. Open appsettings.json in both the Receiver and Sender projects and set AzureServiceBusConnectionString to the connection string for your Azure Service Bus namespace. ![]() Open SendReceiveWithNservicebus.sln in your favorite code editor (For example, Visual Studio 2019). The following diagram, generated by ServiceInsight, a visualization and debugging tool from Particular Software, shows the message flow: ![]() Shared: a class library containing the message contracts shared between the sender and receiver.Receiver: a console application that receives messages from the sender and replies back.Sender: a console application that sends messages.The solution SendReceiveWithNservicebus.sln consists of three projects: Download and prepare the solutionĭownload the code from the Particular Software Docs web site. NServiceBus requires at least the Standard tier.
0 Comments
Read More
Leave a Reply. |