Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about native message access for ASQ #6838

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Snippets/ASQ/ASQN_10/AccessToNativeMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NServiceBus.Pipeline;
using Azure.Storage.Queues.Models;

namespace ASQN_10
{
public class AccessToNativeMessage
{
#region access-native-incoming-message

class DoNotAttemptMessageProcessingIfMessageIsNotLocked : Behavior<ITransportReceiveContext>
{
public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
{
var NextVisibleOnUtc = context.Extensions.Get<QueueMessage>().NextVisibleOn;

if (NextVisibleOnUtc <= DateTime.UtcNow)
{
return next();
}

throw new Exception($"Message lock lost for MessageId {context.Message.MessageId} and it cannot be processed.");
}
}

#endregion
}
}
32 changes: 32 additions & 0 deletions Snippets/ASQ/ASQN_12/AccessToNativeMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NServiceBus.Pipeline;
using Azure.Storage.Queues.Models;

namespace ASQN_12
{
public class AccessToNativeMessage
{
#region access-native-incoming-message

class DoNotAttemptMessageProcessingIfMessageIsNotLocked : Behavior<ITransportReceiveContext>
{
public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
{
var NextVisibleOnUtc = context.Extensions.Get<QueueMessage>().NextVisibleOn;

if (NextVisibleOnUtc <= DateTime.UtcNow)
{
return next();
}

throw new Exception($"Message lock lost for MessageId {context.Message.MessageId} and it cannot be processed.");
}
}

#endregion
}
}
32 changes: 32 additions & 0 deletions Snippets/ASQ/ASQN_13/AccessToNativeMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NServiceBus.Pipeline;
using Azure.Storage.Queues.Models;

namespace ASQN_13
{
public class AccessToNativeMessage
{
#region access-native-incoming-message

class DoNotAttemptMessageProcessingIfMessageIsNotLocked : Behavior<ITransportReceiveContext>
{
public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
{
var NextVisibleOnUtc = context.Extensions.Get<QueueMessage>().NextVisibleOn;

if (NextVisibleOnUtc <= DateTime.UtcNow)
{
return next();
}

throw new Exception($"Message lock lost for MessageId {context.Message.MessageId} and it cannot be processed.");
}
}

#endregion
}
}
2 changes: 2 additions & 0 deletions menu/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@
Title: Delayed Delivery
- Url: transports/azure-storage-queues/native-integration
Title: Native Integration
- Url: transports/azure-storage-queues/native-message-access
Title: Native Message Access
- Url: transports/azure-storage-queues/native-publish-subscribe
Title: Native Publish Subscribe
- Url: transports/azure-storage-queues/sanitization
Expand Down
9 changes: 9 additions & 0 deletions transports/azure-storage-queues/native-message-access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Native message access
summary: Access native message information with the Azure Storage Queues transport
reviewed: 2024-02-09
component: ASQ
versions: '[10,)'
---

partial: supported-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Access to the native Azure Storage Queue incoming message

Accessing the native azure storage queue incoming message from behaviors and handlers can be beneficial for customizations and recoverability. When a message is received, the transport includes the native `QueueMessage` in the message processing context. You can use the following code to retrieve the message details from a pipeline behavior:
TravisNickels marked this conversation as resolved.
Show resolved Hide resolved

snippet: access-native-incoming-message

The behavior above utilizes the native message’s `NextVisibleOn` property to identify when the message lost its lock due to aggressive prefetching and slow processing. If needed, a [custom recoverability policy](/nservicebus/recoverability/custom-recoverability-policy.md) can be implemented to bypass retry attempts that would inevitably fail because of the lost lock.
TravisNickels marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This document describes how to access native message information with the Azure Storage Queue transport.

- Incoming message access is available on versions 10.x, 12.x, and 13.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Access to the native Azure Storage Queues incoming message

Accessing the native azure storage queue's incoming message from behaviors and handlers can be beneficial for customizations and recoverability. When a message is received, the transport includes the native `QueueMessage` in the message processing context. You can use the following code to retrieve the message details from a pipeline behavior:

snippet: access-native-incoming-message

The above behavior utilizes the native message’s `NextVisibleOn` property to identify when the message lost its lock due to aggressive prefetching and slow processing. If needed, a [custom recoverability policy](/nservicebus/recoverability/custom-recoverability-policy.md) can be implemented to bypass retry attempts that would inevitably fail because of the lost lock.