ServerTools.ServerCommands.AzureStorageQueues
1.0.5.1
dotnet add package ServerTools.ServerCommands.AzureStorageQueues --version 1.0.5.1
NuGet\Install-Package ServerTools.ServerCommands.AzureStorageQueues -Version 1.0.5.1
<PackageReference Include="ServerTools.ServerCommands.AzureStorageQueues" Version="1.0.5.1" />
paket add ServerTools.ServerCommands.AzureStorageQueues --version 1.0.5.1
#r "nuget: ServerTools.ServerCommands.AzureStorageQueues, 1.0.5.1"
// Install ServerTools.ServerCommands.AzureStorageQueues as a Cake Addin
#addin nuget:?package=ServerTools.ServerCommands.AzureStorageQueues&version=1.0.5.1
// Install ServerTools.ServerCommands.AzureStorageQueues as a Cake Tool
#tool nuget:?package=ServerTools.ServerCommands.AzureStorageQueues&version=1.0.5.1
About
ServerCommands facilitates running of units of code or commands remotely. It incorporates principles of messaging architectures used by most messaging tools and frameworks, like Azure Service Bus, AWS SQS, RabbitMQ, or Azure Storage Queues, Apache Kafka without any of the knowledge and configuration expertise to manage such installations and configurations.
This library is a spcific implementation that uses Azure Storage Queues. Other implementations are listed below. If you want to create your own extension skip to the section on How to create your own extension to this library.
Implementations
- Azure Storage Queues
- Azure Service Bus
- AWS SQS (coming soon)
- RabbitMQ (coming soon)
- Apache Kafka (coming soon)
More documentation is available at the ServerCommands.
How to Use
To post a command:
var logger = new DebugLoggerProvider().CreateLogger("default");
var prefix = "sample";
var as_accountname = Environment.GetEnvironmentVariable["AccountName"]; //this is the account name for the Azure Storage
var as_accountkey = Environment.GetEnvironmentVariable["AccountKey"]; //this is the account key for the Azure Storage
var connection_options = new AzureStorageQueuesConnectionOptions(as_accountname, as_accountkey, MaxDequeueCountForError: 3, Log: logger, QueueNamePrefix: prefix);
var c = await new CloudCommands().InitializeAsync(new CommandContainer(), connection_options);
_ = await c.PostCommandAsync<AddNumbersCommand>(new { Number1 = 2, Number2 = 3 });
//or _ = await c.PostCommandAsync(typeof(AddNumbersCommand), new { Number1 = 2, Number2 = 3 });
To execute commands, responses or deadletter queues:
var logger = new DebugLoggerProvider().CreateLogger("default");
var retry_policy = Policy
.Handle<Exception>()
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (result, timeSpan, retryCount, context) =>
{
logger?.LogWarning($"Calling service failed [{result.Message} | {result.InnerException?.Message}]. Waiting {timeSpan} before next retry. Retry attempt {retryCount}.");
}); //This is your retry policy. It retries 5 times using exponential backoff. If not set, or set to null, the default is similar: it tries 3 times with exponential backoff
var prefix = "sample"; //this is the prefix that will be added to the queues created by the package
var maxDequeueCountForError = 3; //this is the number of times a message will be dequeued before sent to DLQ. If not set, defaults to 5.
var maxMessagesToRetrieve = 50; //this is the number of messages read by the queue at once. If not set, defaults to 32.
var as_accountname = Environment.GetEnvironmentVariable["AccountName"]; //this is the account name for the Azure Storage
var as_accountkey = Environment.GetEnvironmentVariable["AccountKey"]; //this is the account key for the Azure Storage
var visibilityTimeout = TimeSpan.FromSeconds(20); //this is the amount of time the message will be invisible after if dequeued. If not set, defaults to 60 seconds.
var connection_options = new AzureStorageQueuesConnectionOptions(as_accountname, as_accountkey, , MaxDequeueCountForError: 3, Log: logger, RetryPolicy:retry_policy, QueueNamePrefix: prefix, MaxMessagesToRetrieve: maxMessagesToRetrieve, VisibilityTimeout: visibilityTimeout);
var _container = new CommandContainer();
_container
.Use(logger)
.RegisterCommand<AddNumbersCommand>()
.RegisterResponse<AddNumbersCommand, AddNumbersResponse>();
var c = await new CloudCommands().InitializeAsync(_container, connection_options);
var result = await c.ExecuteCommandsAsync();
//check if something was wrong or if any items were processed at all
Assert.IsTrue(!result.Item1);
//check if 1 or more items were processed
Assert.IsTrue(result.Item2 > 0);
//check if there was any errors
Assert.IsTrue(result.Item3.Count > 0); //This value keeps the list of error messages that were encountered. After retrying 3 times the command is moved to the deadletterqueue.
//If a command generates a response, than you also execute and responses:
var responses = commands.ExecuteResponsesAsync();
Assert.IsTrue(!responses.Item1);
Assert.IsTrue(responses.Item2 > 0);
And that's that!
For more detailed documentation and more complex use cases head to the offical documentation at the GitHub repo. If there are questions or request new feautures do not hesitate to post them there.
How to create your own implementation
To create your own implementation of this functionality, using your own messaging service or storage, go to the base package Server.ServerCommands and follow the instructions there.
Key Features
- Cross-usability between services
- Cross-functionality between clouds or on-prem
- Enhanced simplicity
- Asynchroneous remote execution
- Batching and correlation of commands
- Commands with remote response execution
- High performance
- Supports .NET 6.0+
Related Packages
- Azure.Storage.Queues: GitHub | Nuget
- Microsoft.Extensions.Logging: Nuget
- DryIoc: GitHub | Nuget
- Polly: GitHub | Nuget
Feedback
ServerCommands is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Azure.Storage.Queues (>= 12.11.0)
- ServerTools.ServerCommands (>= 1.0.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Some release notes