AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/servicecontrol/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Using ServiceControl Events

ServiceControl publishes events that enable the creation of custom notifications and integrations to monitor the health of the system. ServiceControl processes messages from the error queue as well as data sent by endpoints using the NServiceBus.Heartbeat and NServiceBus.CustomChecks packages. When messages fail, heartbeats stop arriving, or custom checks fail, ServiceControl publishes events that any subscribing endpoint can react to.

See Monitor with ServiceControl events for a sample.

MessageFailed events

Once a message arrives in the error queue, ServiceControl will publish a MessageFailed event. This message contains:

  • The endpoint that sent the message
  • The endpoint that received the message
  • The cause of the failure (i.e. the exception type and message)
  • The original message headers
  • The original message body, in some cases (see below)

Whether the event includes the body depends on the storage the Error instance uses and on the body itself:

StorageMessage bodyIncluded in the event
RavenDBText, smaller than 85 KB, with full-text body indexing enabledThe full body
RavenDBAny other bodyNo body
SQL Server or PostgreSQLText, up to ServiceControl/MaxBodySizeToStore bytesThe full body
SQL Server or PostgreSQLText, larger than MaxBodySizeToStore bytesThe start of the body, truncated to at most MaxBodySizeToStore bytes
SQL Server or PostgreSQLNot text, such as binary or compressed bodiesNo body

See which bodies count as text for SQL Server and PostgreSQL storage.

Subscribe

It is possible to subscribe to this event type and act on the messages, for example: by sending an email or triggering a text message.

To subscribe to the MessageFailed event:

  1. Create an NServiceBus endpoint.
  2. Install the ServiceControl.Contracts NuGet package.
  3. Configure the endpoint to use SystemJsonSerializer as the message published by ServiceControl uses JSON serialization. Configure the endpoint with the following conventions, as the events published by ServiceControl do not derive from IEvent.
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
var conventions = endpointConfiguration.Conventions();
conventions.DefiningEventsAs(
    type =>
    {
        return typeof(IEvent).IsAssignableFrom(type) ||
               // include ServiceControl events
               type.Namespace != null &&
               type.Namespace.StartsWith("ServiceControl.Contracts");
    });
  1. Add a message handler for the MessageFailed event in the endpoint. In the following example, there is a simple HTTP call to show how to integrate with a third-party system to provide notification of the error.
class MessageFailedHandler :
    IHandleMessages<MessageFailed>
{
    public Task Handle(MessageFailed message, IMessageHandlerContext context)
    {
        var failedMessageId = message.FailedMessageId;
        var exceptionMessage = message.FailureDetails.Exception.Message;

        var chatMessage = $@"Message with id: {failedMessageId} failed.
Reason: '{exceptionMessage}'.
Open in ServicePulse: {GetServicePulseUri(failedMessageId)}";

        using (var client = new ChatClient())
        {
            client.PostChatMessage(chatMessage);
        }
        return Task.CompletedTask;
    }

Registering the publisher for message-driven publish/subscribe

Transports that use message-driven publish-subscribe must have the ServiceControl instance registered as the publisher of the MessageFailed event.

The routing config code API can be used:

var routing = transport.Routing();
routing.RegisterPublisher(typeof(ServiceControl.Contracts.MessageFailed).Assembly, "Particular.ServiceControl");

Monitoring events

ServiceControl will also publish events based on collected monitoring data.

See Heartbeat Notification Events and Custom Check Notification Events for a description of these events.

Other events

ServiceControl will also publish events related to archiving and retrying messages:

  • FailedMessagesArchived: Event emitted for failed messages that were archived, indicating they won’t be retried
  • FailedMessagesUnArchived: Event emitted for failed messages that were un-archived (restored from the archive), making them eligible for retry or further action
  • MessageFailureResolvedByRetry: Event emitted by ServiceControl for each failed message that succeeded after retrying
  • MessageFailureResolvedManually: Event emitted by ServiceControl for each failed message that was manually marked as resolved, typically via the "Resolve" or "Resolve All" actions in ServicePulse
  • MessageEditedAndRetried: Event emitted by ServiceControl every time that a failed message was edited and retried

Decommissioning subscribers to ServiceControl events

ServiceControl uses event publishing to expose information to subscribers. When using a persistence-based transport an internal reference will be kept to each subscriber. If a subscriber for an event cannot be contacted then a log entry will be written with the following error:

Failed dispatching external integration event

An event will also be published and displayed in the ServicePulse dashboard with the following text:

'EVENTTYPE' failed to be published to other integration points. Reason for failure: REASON.

To avoid this situation, it is important to properly decommission an endpoint that subscribes to ServiceControl events. To do this, disable auto-subscription and then unsubscribe from all events.

Enabling publishing

In ServiceControl version 7 and later, publishing is disabled by default. To publish events, set EnableExternalIntegrationsPublishing to true. Leave publishing disabled in systems that have no subscribers for ServiceControl events, to avoid unneeded traffic to the broker.

  • Ingestion-only workers: set the same value on every ingestion-only worker. Each worker stores the MessageFailed events for the messages it ingests, and the Error instance publishes them. A worker without the setting stores none, so failures it ingests publish no MessageFailed event, without any error.

List of Samples

Related Articles