-
Notifications
You must be signed in to change notification settings - Fork 12
What if I can't handle the message right now?
joefeser edited this page Mar 3, 2013
·
2 revisions
If you are unable to handle the message and you want to be called back at a later time, all you need to do is throw an unhandled exception from your code.
You should make sure you set the PauseTimeIfErrorWasThrown property (in milliseconds) so you do not get called right back. If you throw an error, you will not be called back for 15 seconds. The hope is you are able to handle the message at that time.
[MessageHandlerConfiguration(
DefaultMessageTimeToLive = 240,
LockDuration = 120,
MaxRetries = 20,
PauseTimeIfErrorWasThrown = 15000,
PrefetchCount = 10,
ReceiveMode = ReceiveMode.PeekLock,
Singleton = true)]
public class TestMessageSubscriber : IHandleMessages<TestMessage> {
static Logger logger = LogManager.GetCurrentClassLogger();
//You may optionally create a constructor that takes in parameters that can be resolved from your DI container.
public void Handle(IReceivedMessage<TestMessage> message) {
logger.Log(LogLevel.Info, "Message received: {0} {1}", message.Message.Value, message.Message.MessageId);
//If you can't deal with the message and you would like to be called back, throw an exception.
throw new Exception("I am having a bad day.");
}
}
See this for more information on configuring the receiver.