Created
July 22, 2021 23:34
-
-
Save samuelsherrer/5eabf30d737d9b961a481fbbbb5a3627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ServiceBusMessageExtensions | |
{ | |
public const string RetryCountIdentifier = "RetryAttempt"; | |
public static bool ShouldRetry(this Message message, int maxRetryCount) | |
{ | |
int resubmitCount = message.GetRetryAttempt(); | |
return resubmitCount < maxRetryCount; | |
} | |
public static void IncreaseRetryAttempt(this Message message) | |
{ | |
int retryCount = message.GetRetryAttempt(); | |
message.UserProperties[RetryCountIdentifier] = retryCount + 1; | |
} | |
public static int GetRetryAttempt(this Message message) | |
{ | |
return message.UserProperties.ContainsKey(RetryCountIdentifier) ? (int)message.UserProperties[RetryCountIdentifier] : 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment