fissolue.SimpleQueue.FluentNHibernate 1.0.1

dotnet add package fissolue.SimpleQueue.FluentNHibernate --version 1.0.1                
NuGet\Install-Package fissolue.SimpleQueue.FluentNHibernate -Version 1.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="fissolue.SimpleQueue.FluentNHibernate" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add fissolue.SimpleQueue.FluentNHibernate --version 1.0.1                
#r "nuget: fissolue.SimpleQueue.FluentNHibernate, 1.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 fissolue.SimpleQueue.FluentNHibernate as a Cake Addin
#addin nuget:?package=fissolue.SimpleQueue.FluentNHibernate&version=1.0.1

// Install fissolue.SimpleQueue.FluentNHibernate as a Cake Tool
#tool nuget:?package=fissolue.SimpleQueue.FluentNHibernate&version=1.0.1                

SimpleQueue - a simple database-backed queue implementation for .NET

Features

SimpleQueue is a NuGet library that you can add in to your project that will allow you to persist objects into one or more queues. The current implementation is based on Fluent NHibernate, so you can use this implementation on top of all the databases NHibernate currently supports (MS SQL Server 2005 and above, Oracle, Microsoft Access, Firebird, PostgreSQL, DB2 UDB, MySQL, SQLite). An Entity Framework version is forthcoming.

You can decide the best way to persist the data - all have advantages and disadvantages. You can use .NET's binary serialization, JSON.net serialization, the DataContractJsonSerializer, or XML. For binary serialization, any complex objects must be tagged with the [Serializable] attribute.

Once initialized, there are five core methods:

  • Enqueue an object
  • Dequeue an object (note that any dequeued object may be dequeued again if you fail to call the Acknowledge method after using it. It will become invisible to all clients for a default of 30 seconds.)
  • Acknowledge. This means you're done with your processed an dequeued item so it won't become visible to clients again.
  • Extend. After you've dequeued an item, call this method at any time if you need more time to process it before it automatically goes back into the pool.
  • Purge. This removes ALL acknowledged items from persistence and should only be called periodically to clean up the database tables.

Example usage:

using System;
using System.ComponentModel;	
using System.IO;
using System.Threading;
using fissolue.SimpleQueue.EntityFramework;
using fissolue.SimpleQueue.FluentNHibernate;
using FluentNHibernate.Cfg.Db;

public class Program
{
    private static void Main(string[] args)
    {
	    IPersistenceConfigurer configurer = MsSqlConfiguration.MsSql2012.ConnectionString("Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;");
		
		//this creates a queue that stores <int> data type, but you could replace it with anything that will serialize. 
		var myQueue = new FluentNHibernateQueue<int>("dummyQueue", configurer, true, new LocalOptions<int> {SerializationType = SerializationTypeEnum.NewtonsoftJson});
		
		//ok, enqueue some items
		for(var i = 0; i<10; i++){
		    myQueue.Enqueue(i);
		}
		
		//now, de-queue them
		while(true)
		{
		    var dequeuedItem = myQueue.Dequeue();
			if (dequeuedItem == null)
			{
				//queue is empty
				break;
			}
			Console.WriteLine(dequeuedItem.Data); //Data property contains the values
			
			//do more processing here with whatever you pulled out of the queue
			
			//now let the db know you're done with the item.
			myQueue.Acknowledge(dequeuedItem.AckId);
		}
		//Clean up
		myQueue.Purge();
	}
}            

By default, a dequeued item will revert back to enqueued if you don't call the Acknowledge method for it within 30 seconds. To get around this, you can (a) pass a timespan of your choosing as an argument to the Dequeue method, or (b) in the LocalOptions object used to initialize the queue, use the Visibility property to set a default timespan. This mechanism is here essentially so if your process dies, the item stays in the queue.

Sharable on Multiple Clients

Because this is database-backed, you can point multiple processes to it, even if they run on different machines. This implementation intentionally does NOT use database transactions, because we want to avoid deadlock situations.

Code-First Approach

A key feature of SimpleQueue is the fact that you don't even need to bother creating tables in the database. It uses only TWO tables, and you can have as many queues (uniquely named) as you like. In your database of choice, you must have table creation permissions if the SimpleQueue tables don't exist already.

RDMBS Support

Fluent NHibernate supports MS SQL Server with no additional libraries required. For the other databases, your application must include the 'standard' data provider package (from Nuget or otherwise) for the database provider (i.e. MySQL.Data, System.Data.SQLite). Whatever the case, you'll just pass an instance of IPersistenceConfigurer so SimpleQueue knows where to put its data. More info: https://github.com/jagregory/fluent-nhibernate/wiki/Database-configuration

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.

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
1.0.1 1,194 11/21/2017
1.0.0 854 11/21/2017

Corrected name of main queue object