Code Monkey home page Code Monkey logo

grumpy.messagequeue's Introduction

Build status codecov nuget downloads

Grumpy.MessageQueue

API for Microsoft Message Queue (MSMQ).

This API extents the API with:

  • Larger messages (Move the limit from 4MB to the size of a string 1-2GB)
  • Transactional messages with Ack and NAck feature
  • Queue Handler (Listener) to trigger handler method when messages are received
  • Automatic management of queues (Create and Delete)
  • Cancelable Receiver
  • Async Receiver

This API includes the features that are most used (and needed for my other solution). The API makes the use of MSMQ easy and strait forward. I know this library is opinionated and only provide a sub set of the features in MSMQ API for Microsoft Message Queue (MSMQ).

Send and Receive

The following code sample will:

  • Create a new Private Queue on the current maschine, if not exists
  • Open a connections to the queue
  • Send a Message
  • Receive the same message
  • Close the connection
var queueFactory = new QueueFactory();

using (var queue = queueFactory.CreateLocale("MyQueue", true, LocaleQueueMode.DurableCreate, true)) 
{
    // Message will be serialized to json and chumped into pieces, all pieces send in the same transaction
    queue.Send("MyMessage");

    // The receive has a timeout of 1 sec, and the message will be deserialized to the type (here string). This receive will automatically Ack the message
    var response = queue.Receive<string>(1000, new CancellationToken());
}

Receive and Ack

The following code sample will:

  • Receive a transactional message
  • Try to Handle the message in some other method
  • If any exception, NAck the message for next receive to handle the samme message
var queueFactory = new QueueFactory();

using (var queue = queueFactory.CreateLocale("MyQueue", true, LocaleQueueMode.Durable, true)) 
{
    var message = queue.Receive(1000, new CancellationToken());

    try {
        Handle(messege.Message)
        message.Ack();
    }
    catch
    {
        message.NAck();
    }
}

Queue Handler (Listerner)

The following code sample will:

  • Create a Queue handler
  • Start Listening to a Queue
  • For each message call the method MessageHandler
  • Ack and NAck are handled in the QueueHandler
var queueFactory = new QueueFactory();
var queueHandlerFactory = new QueueHandlerFactory(queueFactory);

using (var queueHandler = queueHandlerFactory.Create()) 
{
    queueHandler.Start("MyQueue", true, LocaleQueueMode.Durable, true, MessageHandler, null, null, 0, true, false, new CancellationToken());

    // Wait for ever, or until cancelled
}

public void MessageHandler(object message, CancellationToken cancellationToken) 
{
    // Do stuff with message
}

Just ask for more samples!!!

grumpy.messagequeue's People

Contributors

grumpybusted avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.