How to debug both Handle
methods below?
I set breakpoints on both Handle
method within Visual Studio, and send message to Subscriber1
queue, but both methods are not called under VS.
public class SomeHandler : IHandleMessages<string>, IHandleMessages<IFailed<string>>
{
readonly IBus _bus;
public SomeHandle(IBus bus)
{
_bus = bus;
}
public async Task Handle(string message)
{
// do stuff that can fail here...
}
public async Task Handle(IFailed<string> failedMessage)
{
await _bus.Advanced.TransportMessage.Defer(TimeSpan.FromSeconds(30));
}
}
Below is the message sent to Subscriber1
.
I tried sending the message excluding either rbs2-msg-id
or rbs2-msg-type
, neither of them triggers the Handle
method above.
{
"body": "Test",
//other fields
"properties": {
"rbs2-intent": "pub",
"rbs2-msg-id": "cd57d735-3989-45b5-8a3c-e457fa61dc94",
"rbs2-return-address": "publisher",
"rbs2-senttime": "2019-05-27T15:07:25.1770000+01:00",
"rbs2-sender-address": "publisher",
"rbs2-msg-type": "System.String, mscorlib",
"rbs2-corr-id": "cd57d735-3989-45b5-8a3c-e457fa61dc94",
"rbs2-corr-seq": "0",
"rbs2-content-type": "application/json;charset=utf-8"
},
//other fields
}
Update 1
If an exception is thrown within Handle(string message)
, the method will be retried based on the 1st level try count. This is what we need.
However, Handle(IFailed<string> failedMessage)
is not invoked, how to debug Handle(IFailed<string> failedMessage)
like abvoe?
One note: when an exception is thrown within Handle(string message)
, IErrorHandler is NOT called, and AddTransportMessageForwarder is not called either, are these correct?
Could you try and check your logs?
When you remove the rbs2-msg-id
header, Rebus will immediately move the message to the dead-letter queue, simply refusing to handle it. This is because a message without a message ID cannot be tracked by Rebus' error tracker.
If you remove the rms2-msg-type
header, the serializer will most likely throw an error and not deserialize the incoming message.
In both cases, the error will be output to the logger.
And in both cases, the message body (string
in this case, but it could be any message type) cannot be constructed from the incoming
byte[], so Rebus cannot dispatch the message as either
stringnot
IFailed`.
Edit after Update 1:
If your 2nd level retries do not kick in, it's most likely because you haven't enabled them:
Configure.With(...)
.(...)
.Options(o => o.SimpleRetryStrategy(secondLevelRetriesEnabled: true))
.Start();
IErrorHandler
is called when it is time to move the message to the dead-letter queue. You should see it being called, when all delivery attempts have failed (5 normal delivery attempts + 5 2nd level delivery attempts).
If you've configured things the way I suggested it, AddTransportMessageForwarder
is used in another bus instance, which receives messages from the error
queue. When IErrorHandler
has been called, and the failed messge has been forwarded to the queue error
, then your transport message forwarder should be called.