Using NServiceBus 4.3 I want to send a message to the error queue when certain conditions arise.
The scenario is that when I get a message in I check if this message is referring to 1 or more items in our database. If there are multiple references I throw a AmbiguousItemException
and catch it. I need to email the person responsible for giving me the correct information. All of that is figured out but I don't want this message to be tried again. Instead I'd rather move it to the error Queue so when we get back the information we need we can add in the nullable property and put the message back into the queue for processing. I've tried using _bus.ForwardCurrentMessageTo("error")
, _bus.Send("error", message)
, _bus.SendLocal(message)
. The last one basically puts the message in an infinite loop. The code is kind of like this.
public class MoveToErrorQueue
{
private readonly IBus _bus;
public MoveToErrorQueue(IBus bus)
{
_bus = bus;
}
public virtual void Send(ResubmitMessage message)
{
message.Foo= -1;
_bus.Send("error", message);
}
}
and the code that calls it
try
{
//removed for brevity
}
catch (AmbiguousItemException ex)
{
Log.Error(ex);
sendNotificationCommand.FailureMessage = ex.Message;
_moveToErrorQueue.Send(commandMesage);
}
SendNotification(sendScanningNotificationCommand);