CloudNimble.WebJobs.Extensions.Common 1.0.0-CI-20250608-015954

Prefix Reserved
This is a prerelease version of CloudNimble.WebJobs.Extensions.Common.
dotnet add package CloudNimble.WebJobs.Extensions.Common --version 1.0.0-CI-20250608-015954
                    
NuGet\Install-Package CloudNimble.WebJobs.Extensions.Common -Version 1.0.0-CI-20250608-015954
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CloudNimble.WebJobs.Extensions.Common" Version="1.0.0-CI-20250608-015954" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CloudNimble.WebJobs.Extensions.Common" Version="1.0.0-CI-20250608-015954" />
                    
Directory.Packages.props
<PackageReference Include="CloudNimble.WebJobs.Extensions.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CloudNimble.WebJobs.Extensions.Common --version 1.0.0-CI-20250608-015954
                    
#r "nuget: CloudNimble.WebJobs.Extensions.Common, 1.0.0-CI-20250608-015954"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CloudNimble.WebJobs.Extensions.Common@1.0.0-CI-20250608-015954
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CloudNimble.WebJobs.Extensions.Common&version=1.0.0-CI-20250608-015954&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CloudNimble.WebJobs.Extensions.Common&version=1.0.0-CI-20250608-015954&prerelease
                    
Install as a Cake Tool

CloudNimble.WebJobs.Extensions.Common

NuGet License: MIT

Overview

CloudNimble.WebJobs.Extensions.Common provides a robust foundation for building cloud-agnostic Azure WebJobs extensions. This package contains base classes, interfaces, and utilities that enable you to create reliable, scalable queue processing solutions that work across different cloud providers.

Features

  • Queue Processing Framework: Generic queue listener and processor implementations with built-in retry logic and poison message handling
  • Flexible Type Conversion: Comprehensive converter system for seamless message deserialization
  • Advanced Timing Strategies: Exponential backoff, linear speedup, and customizable delay strategies
  • Metrics and Monitoring: Built-in metrics providers for queue depth monitoring and autoscaling
  • Dependency Injection Ready: Full support for modern .NET dependency injection patterns
  • Thread-Safe Operations: Context accessors and shared listeners for safe concurrent processing

Installation

dotnet add package CloudNimble.WebJobs.Extensions.Common

Key Components

Queue Processing

The library provides a complete queue processing pipeline:

// Custom queue processor with advanced error handling
public class MyQueueProcessor : QueueProcessor<MyMessage>
{
    protected override async Task<bool> BeginProcessingMessageAsync(
        MyMessage message, 
        CancellationToken cancellationToken)
    {
        try
        {
            // Your processing logic here
            await ProcessBusinessLogic(message);
            return true; // Message processed successfully
        }
        catch (TransientException)
        {
            return false; // Retry the message
        }
    }
    
    protected override async Task CompleteProcessingMessageAsync(
        MyMessage message, 
        FunctionResult result, 
        CancellationToken cancellationToken)
    {
        if (result.Succeeded)
        {
            // Clean up or audit successful processing
            await LogSuccess(message);
        }
    }
}

Type Converters

Create custom converters for your message types:

public class CustomMessageConverter : IAsyncObjectToTypeConverter<IQueueMessage>
{
    public async Task<ConversionResult<TOutput>> TryConvertAsync<TOutput>(
        IQueueMessage input, 
        CancellationToken cancellationToken)
    {
        if (typeof(TOutput) == typeof(MyCustomType))
        {
            var json = await input.GetBodyAsync(cancellationToken);
            var result = JsonSerializer.Deserialize<MyCustomType>(json);
            return ConversionResult<TOutput>.Success((TOutput)(object)result);
        }
        
        return ConversionResult<TOutput>.Failure();
    }
}

Delay Strategies

Implement custom backoff strategies for retry scenarios:

public class CustomDelayStrategy : IDelayStrategy
{
    public TimeSpan GetNextDelay(bool executionSucceeded, TimeSpan currentDelay)
    {
        if (executionSucceeded)
        {
            return TimeSpan.Zero; // No delay on success
        }
        
        // Custom backoff logic
        return TimeSpan.FromSeconds(Math.Min(currentDelay.TotalSeconds * 2, 300));
    }
}

Metrics and Scaling

Implement queue metrics for autoscaling:

public class MyQueueMetricsProvider : IQueueMetricsProvider
{
    public async Task<QueueProperties> GetQueuePropertiesAsync(
        string queueName, 
        CancellationToken cancellationToken)
    {
        var messageCount = await GetMessageCountFromService(queueName);
        
        return new QueueProperties
        {
            ApproximateMessagesCount = messageCount,
            QueueLength = messageCount
        };
    }
}

Integration with WebJobs

The Common package integrates seamlessly with Azure WebJobs:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Register your custom implementations
        services.AddSingleton<IQueueProcessorFactory, DefaultQueueProcessorFactory>();
        services.AddSingleton<IDelayStrategy, RandomizedExponentialBackoffStrategy>();
        
        // Configure queue processing options
        services.Configure<QueueProcessorOptions>(options =>
        {
            options.MaxDequeueCount = 5;
            options.VisibilityTimeout = TimeSpan.FromMinutes(5);
            options.MaxPollingInterval = TimeSpan.FromSeconds(30);
        });
    }
}

Advanced Scenarios

Poison Message Handling

public class PoisonMessageHandler
{
    public async Task HandlePoisonMessageAsync(PoisonMessageEventArgs args)
    {
        // Log the poison message
        await LogPoisonMessage(args.Message, args.Exception);
        
        // Move to dead letter queue
        await MoveToDeadLetterQueue(args.Message);
        
        // Send alert
        await NotifyOperations(args);
    }
}

Context Sharing

Share context across different components:

public class RequestContextAccessor : ContextAccessor<RequestContext>
{
    // Automatically provides thread-safe access to RequestContext
}

// Usage
services.AddScoped<IContextGetter<RequestContext>, RequestContextAccessor>();
services.AddScoped<IContextSetter<RequestContext>>(
    provider => provider.GetService<RequestContextAccessor>());

Best Practices

  1. Use Dependency Injection: Leverage the built-in DI support for better testability
  2. Implement Proper Retry Logic: Use the provided delay strategies or create custom ones
  3. Monitor Queue Metrics: Implement metrics providers for visibility and autoscaling
  4. Handle Poison Messages: Always implement poison message handling to prevent message loss
  5. Use Type Converters: Create converters for your custom types to maintain clean code

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Made with ❤️ by CloudNimble

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CloudNimble.WebJobs.Extensions.Common:

Package Downloads
CloudNimble.WebJobs.Extensions.Amazon

Allows you to ren Azure WebJobs using AWS SQS triggers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-CI-20250608-015954 82 6/8/2025
1.0.0-CI-20250608-013940 79 6/8/2025
1.0.0-CI-20250608-012213 80 6/8/2025
1.0.0-CI-20250606-232418 40 6/7/2025