Skip to content

Nuages.TaskQueue is a .NET Core C# library that provides functionalities to execute code based on a task definition that are poll from a queue.

License

Notifications You must be signed in to change notification settings

nuages-io/nuages-taskqueue

Repository files navigation

Nuages.TaskQueue

Nuages.TaskQueue Nuages.TaskQueue Nuages.TaskQueue

example workflow

Nuages.TaskQueue bring Nuages.TaskRunner and Nuages.Queue together to offer a hosted task running service based on message from a queue.

It is available in two packages :

  • Nuages.TaskQueue.SQS for AWS Simple Queue Service (nuget | source)
  • Nuages.TaskQueue.ASQ for Azure Storage Queue (nuget | source)

How to use with SQS

Configuration

//Default SQS configuration
//You can provide your own implementation of IQueueClientProvider if you want to provide the instance using another way.
services.AddDefaultAWSOptions(configuration.GetAWSOptions())
        .AddAWSService<IAmazonSQS>();
        
services.AddSQSTaskQueueWorker(configuration);

appsettings.json

{
  "Queues":
  {
    "AutoCreateQueue" : true
  },
  "TaskQueueWorker" :
  {
    "QueueName" : "here-you-enter-your-queuename",
    "Enabled" : true,
    "MaxMessagesCount" : 1,
    "WaitDelayInMillisecondsWhenNoMessages": 2000
  },
  "AWS": {
    "Profile": null,
    "Region": null
  }
}

Alternatively, you may want to provide the value using the Configure method.

services.AddSQSTaskQueueWorker(configuration)
        .Configure<QueueOptions>(options =>
        {
            //set options here  
        }).Configure<QueueWorkerOptions>(options =>
        {
          //set options here  
        });
        

Push message to the queue

You can push message on the queue the way you want. The important thing here is that the queue message body can be deserialize as a RunnableTaskDefinition.

This is what it should look like.

{
  "AssemblyQualifiedName": "Nuages.TaskRunner.Tasks.OutputToConsoleTask, Nuages.TaskRunner, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
  "Payload": { "Message" : "Started !!!!" }
}

A service is provided to help you push such a message from your code. You need to use ISQSQueueService for that.

var data = new OutputToConsoleTaskData { Message = message };
var taskData = RunnableTaskDefinitionCreator<OutputToConsoleTask>.Create(data);

//ISQSQueueService _isqsQueueService injected using DI
await _isqsQueueService.EnqueueTaskAsync("queue-name-goes-here", taskData);
        

Samples

About

Nuages.TaskQueue is a .NET Core C# library that provides functionalities to execute code based on a task definition that are poll from a queue.

Topics

Resources

License

Stars

Watchers

Forks