Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Use Bridge to connect to ServiceControl running on different transport

Component: Messaging Bridge
NuGet Package: NServiceBus.MessagingBridge (3.x)
Target Version: NServiceBus 9.x

This sample shows how to configure ServiceControl to monitor endpoints and retry messages when using mixed transports. Both the endpoint and the ServiceControl instance use the learning transport (so that external dependencies are not needed) but with different storage folders. The same approach can be used to connect a single ServiceControl instance to multiple instances of the same transport, e.g. multiple databases used for SQL Server transport or to different transports.

Running the project

  1. Start the Bridge, Endpoint and PlatformLauncher projects. ServicePulse should open automatically in the default browser.
  2. Go to the Endpoint console window and press o to send a message.
  3. Notice the endpoint receives its own message and successfully processes it.
  4. Press f to simulate message processing failure.
  5. Press o in to create more messages.
  6. Notice this time messages fail to be processed.
  7. Go to ServicePulse in the web browser and select the Failed Messages view.
  8. Notice the existence of one failed message group with two messages. Open the group.
  9. Press f in the Endpoint console to disable the failure simulation.
  10. Press the Retry all button in ServicePulse.
  11. Go to the Endpoint console and verify that the message has been successfully processed.
  12. Shut down the Endpoint.
  13. Open ServicePulse and notice a red label next to the heart icon. Click on that icon to open the Endpoints Overview. Notice that the Endpoint is now displayed in the Inactive Endpoints tab.

Code walk-through

The code base consists of three projects.

Endpoint

The Endpoint project contains an endpoint that simulates the execution of a business process by sending a message to itself. It includes a message processing failure simulation mode (toggled by pressing f) which can be used to generate failed messages for demonstrating message retry functionality. It uses the SQL Server transport.

The Endpoint has the heartbeats plugin installed to enable uptime monitoring via ServicePulse.

Bridge

The Bridge project hosts the NServiceBus.MessagingBridge. The bridge has two sides: endpoint-facing and ServiceControl-facing.

var serviceControlTransport = new BridgeTransport(new LearningTransport());
serviceControlTransport.HasEndpoint("Particular.ServiceControl");
serviceControlTransport.HasEndpoint("Particular.Monitoring");
serviceControlTransport.HasEndpoint("error");
serviceControlTransport.HasEndpoint("audit");
var learningTransport = new LearningTransport
{
    // Set storage directory and add the character '2' to simulate a different transport.
    StorageDirectory = $"{LearningTransportInfrastructure.FindStoragePath()}2"
};

var endpointsTransport = new BridgeTransport(learningTransport)
{
    // A different name is required if transports are used twice.
    Name = "right-side"
};

endpointsTransport.HasEndpoint("Samples.Bridge.Endpoint");

Duplicates

The bridge might introduce duplicates in the message flow when bridging two transports so endpoints need to account for that, e.g. by enabling the Outbox feature.

Related Articles

  • Messaging Bridge
    Connect endpoints in a system that use different transports with the messaging bridge.
  • ServiceControl
    An overview of ServiceControl and what it does.