Consumidor 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Consumidor --version 2.0.1                
NuGet\Install-Package Consumidor -Version 2.0.1                
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="Consumidor" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Consumidor --version 2.0.1                
#r "nuget: Consumidor, 2.0.1"                
#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.
// Install Consumidor as a Cake Addin
#addin nuget:?package=Consumidor&version=2.0.1

// Install Consumidor as a Cake Tool
#tool nuget:?package=Consumidor&version=2.0.1                

Consumidor alternate text is missing from this package README image

A simple library to implements producer-consumer pattern

Overview

It's a library to give a simple way for implement producer and consumer pattern. Allowing the complex away from your code and time to focus in your task. All consumers and producer will run in a separate task, doing concurrency management for you.

Usage

Producer

 class Producer : IProducer<int>
    {
        public Producer()
        {
            Collection = new ConcurrentQueue<int>();
        }

        public ConcurrentQueue<int> Collection { get; set; }

        public void RefreshCollection()
        {
            for (int i = 0; i < 15; i++)
                Collection.Enqueue(i);
        }
    }

Consumer

 class Consumer : IConsumer<int>
    {
        public string Id { get; set; }

        public void Process<T>(T item) => Console.WriteLine($"Consumer {Id} - processing item {item}");
    }

Starting

            var producer = new Producer();
            var consumers = new List<Consumer>()
            {
                new Consumer { Id = "Consumer 1" },
                new Consumer { Id = "Consumer 2" },
                new Consumer { Id = "Consumer 3" },
                new Consumer { Id = "Consumer 4" },
                new Consumer { Id = "Consumer 5" },
            };

            var service = new Service<int>(producer, consumers);            
            service.Start();
            Console.WriteLine("Press something to stop producer");
            Console.ReadLine();
            service.ProducerCancelationTokenSource.Cancel();

            Console.WriteLine("Press something to stop consumers");
            Console.ReadLine();
            service.ConsumerCancelationTokenSource.Cancel();
            Console.WriteLine("Done!");
            Console.ReadKey();

Options

You can define:

  • ConsumerIntervalDelay;
  • ProducerRefreshIntervalDelay;
  • ProducerRefreshTimes;
  • ThrowExceptionOnConsumerError ;
  • ReturnToQueueOnError;
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 427 4/29/2021
2.0.1 936 8/17/2018
2.0.0 822 8/16/2018
1.0.1 834 8/14/2018
1.0.0 829 8/7/2018

Adding a processing list and creating a baseclass to make a producer implementation easy.