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).
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
varqueueFactory=newQueueFactory();using(varqueue=queueFactory.CreateLocale("MyQueue",true,LocaleQueueMode.DurableCreate,true)){// Message will be serialized to json and chumped into pieces, all pieces send in the same transactionqueue.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 messagevarresponse=queue.Receive<string>(1000,newCancellationToken());}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
varqueueFactory=newQueueFactory();using(varqueue=queueFactory.CreateLocale("MyQueue",true,LocaleQueueMode.Durable,true)){varmessage=queue.Receive(1000,newCancellationToken());try{Handle(messege.Message)
message.Ack();}catch{message.NAck();}}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
varqueueFactory=newQueueFactory();varqueueHandlerFactory=newQueueHandlerFactory(queueFactory);using(varqueueHandler=queueHandlerFactory.Create()){queueHandler.Start("MyQueue",true,LocaleQueueMode.Durable,true,MessageHandler,null,null,0,true,false,newCancellationToken());// Wait for ever, or until cancelled}publicvoidMessageHandler(objectmessage,CancellationTokencancellationToken){// Do stuff with message}Just ask for more samples!!!