Skip to content

Instantly share code, notes, and snippets.

@meisinger
meisinger / cooperative-queue-factory.cs
Created June 3, 2014 04:21
factory class to create a connection to rabbit mq along with a consumer and publisher
using RabbitMQ.Client;
using RabbitMQ.Client.Exceptions;
public class MessageQueueFactory : IMessageQueueFactory
{
private readonly ConnectionFactory factory;
private IConnection connection;
public bool IsOpen
{
@meisinger
meisinger / cooperative-consumer.cs
Last active August 29, 2015 14:02
consumer for cooperative queue
using RabbitMQ.Client
public class CooperativeConsumer : IBasicConsumer
{
private readonly IModel channel;
private readonly CooperativeQueue<IQueueMessage> queue;
public IModel Model
{
get { return channel; }
@meisinger
meisinger / task-controller.cs
Created May 29, 2014 03:32
example of a task controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using StructureMap;
namespace Task.Services.Service
{
public class Controller
@meisinger
meisinger / csv-reader.cs
Created May 1, 2014 03:33
example of a simple csv reader
public sealed class CsvReader : IDisposable
{
private const char DefaultFieldChar = ',';
private const char DefaultQuoteChar = '"';
private const char DefaultEscapeChar = '\\';
private readonly List<CsvLine> collection;
private readonly StringBuilder buffer;
private readonly Stream stream;
private readonly StreamReader reader;
@meisinger
meisinger / cooperative-queue.cs
Last active August 29, 2015 14:00
queue with cooperative cancellation
public class CooperativeQueue<TMessage>
where TMessage : class, IQueueMessage
{
private readonly Queue<TMessage> internalQueue;
private readonly ManualResetEventSlim manualReset;
private bool open;
public CooperativeQueue()
{
internalQueue = new Queue<TMessage>();
@meisinger
meisinger / redis-command.cs
Created May 1, 2014 02:34
an approach to creating redis commands
public class RedisCommand
{
static byte[] GenerateCommand(byte[][] arguments)
{
using (var stream = new MemoryStream())
{
var request = CreateIndicator('*', arguments.Length);
stream.Write(request, 0, request.Length);
stream.WriteNewLine();