﻿# Pipeline events


The pipeline raises the following notification events:

## Receive pipeline completed

Every time a receive pipeline is completed, a `ReceivePipelineCompleted` event will be raised. This event will not occur when message processing fails, e.g., inside a handler.

Use the following configuration code to subscribe to the event:

<!-- snippet: ReceivePipelineCompletedSubscriptionFromEndpointConfig -->

```cs
endpointConfiguration.Pipeline.OnReceivePipelineCompleted(
    subscription: (completed, ct) =>
    {
        var duration = completed.CompletedAt - completed.StartedAt;
        log.Info($"Receive completed. Message: {completed.ProcessedMessage.MessageId}, duration: {duration}");
        return Task.CompletedTask;
    });
```

<!-- endsnippet -->

Subscribing from a [feature](/nservicebus/pipeline/features.md) is shown below:

<!-- snippet: ReceivePipelineCompletedSubscriptionFromFeature -->

```cs
var pipeline = context.Pipeline;
pipeline.OnReceivePipelineCompleted(
    subscription: (completed, ct) =>
    {
        var duration = completed.CompletedAt - completed.StartedAt;
        log.Info($"Receive completed: Message: {completed.ProcessedMessage.MessageId}, duration: {duration}");
        return Task.CompletedTask;
    });
```

<!-- endsnippet -->

> [!NOTE]
> A `ReceivePipelineCompleted` event being raised does not guarantee that the message has been removed from the incoming queue. Infrastructure exceptions can still cause the message to be rolled back and reprocessed.
