2
votes

I have an application using NServiceBus to process messages, and while debugging I'm finding that exceptions may be thrown, and the message is lost. I've checked both the main and error queues, and the message was only attempted once.

Are there any common pitfalls that could cause this to happen?

I use NServiceBus 2.0.0.1219 (2.0 RTM) on Windows 7 64 bit. Other question with same issue on older version: What could prevent NServiceBus from moving messages to the error queue if there are exceptions when processing?

The website Bus.Send a command to the command handler endpoint.

Website Config File:

<MsmqTransportConfig InputQueue="WebAppTest_InputQueue" ErrorQueue="ErrorQueue" NumberOfWorkerThreads="1" MaxRetries="5"/>

<UnicastBusConfig ForwardReceivedMessagesTo="AuditQueue">
  <MessageEndpointMappings>
    <add Messages="ABC.ServiceBus.Commands" Endpoint="CommandProcessor_InputQueue"/>
  </MessageEndpointMappings>
</UnicastBusConfig>

<DBSubscriptionStorageConfig>
  ...
</DBSubscriptionStorageConfig>

Command Handler Config File:

<MsmqTransportConfig InputQueue="CommandProcessor_InputQueue" ErrorQueue="ErrorQueue" NumberOfWorkerThreads="1" MaxRetries="5" />

<UnicastBusConfig ForwardReceivedMessagesTo="AuditQueue">
  <MessageEndpointMappings>
    <add Messages="ABC.ServiceBus.Commands" Endpoint="WebAppTest_InputQueue"/>
  </MessageEndpointMappings>
</UnicastBusConfig>

<DBSubscriptionStorageConfig>
  ...
</DBSubscriptionStorageConfig>
1
Can you include your administrative config? Also be sure that MSMQ/DTC is installed correctly for NSB. You can confirm this using the Runner tool in the download(tools\MsmqUtils).Adam Fyles
MSMQ/DTC is installed correclty, thank you for the tip. I added the relevent config file sections in the question.LucG
I'm wondering if it has to do with the message forwarding. Does it still happen if you remove the "ForwardReceivedMessagesTo"? I will try and setup a repro in the meantime.Adam Fyles
Follow-up, if I add the ForwardReceivedMessagesTo, I don't lose the error messages, but I don't get anything in the audit queue.Adam Fyles
I removed the "ForwardReceivedMessagesTo" and the same behavior occurs: The message is attempted once, the logger logs the exception (thrown in the command handler), and the error queue remains empty.LucG

1 Answers

1
votes

Since the message forwarding is part of the same transaction as the receipt of the message, if the receive fails, the forwarding fails. I'm thinking that if an exception is thrown you probably want it to go to the error queue and not the audit queue since it wasn't received correctly. If you want to see everything that flows through irregardless, journaling might be a better bet.