Вопрос

Current Setup includes a windows service which picks up a message from the local queue and extracts the information and puts in to my SQL database.According to my design

  1. Service picks up the message from the queue.(I am using Peek() here).
  2. Sends it to the database.
  3. If for some reason i get an exception while saving it to the database the message is back into the queue,which to me is reliable.
  4. I am logging the errors so that a user can know what's the issue and fix it.

Exception example:If the DBconnection is lost during saving process of the messages to the database then the messages are not lost as they are in the queue.I don't comit untill i get an acknowledgement from the DB that the message is inserted .So a user can see the logs and make sure that the DBconnection exists and every thing would be normal and we dont lose any messages in the queue.

But looking into another scenario:The messages I would be getting in the queue are from a 3rd party according a standard schema.The schema would remain same and there is no change in that.But i have seen some where i get some format exceptions and since its not committed the message is back to the queue.At this point this message would be a bottle neck for me as the same messages is picked up again and tries to process the message.Every time the service would pick up the same message and gets the same exception.So this loops infinitely unless that message is removed or put that message last in the queue.

Looking at removing the message:As of now if i go based on the format exception...then i might be wrong since i might encounter some other exceptions in the future .

Is there a way i can put this messages back to the queue last in the list instead beginning of the queue.

Need some advice on how to proceed further.

Note:Queue is Transactional .

Это было полезно?

Решение

As far as I'm aware, MSMQ doesn't automatically dump messages to fail queues. Either way you handle it, it's only a few lines of code (Bill, Michael, and I recommend a fail queue). As far as a fail queue goes, you could simple create one named .\private$\queuename_fail.

Surviving poison messages in MSMQ is a a decent article over this exact topic, which has an example app and source code at the end.

private readonly MessageQueue _failQueue;
private readonly MessageQueue _messageQueue;
/* Other code here (cursor, peek action, run method, initialization etc) */

private void dumpToFailQueue(Message message)
{
    var oldId = message.Id;
    _failQueue.Send(message, MessageQueueTransactionType.Single);

    // Remove the poisoned message
    _messageQueue.ReceiveById(oldId);
}

private void moveToEnd(Message message)
{
    var oldId = message.Id;
    _messageQueue.Send(message, MessageQueueTransactionType.Single);

    // Remove the poisoned message
    _messageQueue.ReceiveById(oldId);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top