Handling an Unknown Message
In the case where your system receives a message with a message type that you cannot handle,
Jasper gives you the ability to write your own policy about how to deal with that message with the
IMissingHandler
interface shown below:
public interface IMissingHandler
{
Task Handle(Envelope envelope, IMessagingRoot root);
}
To create your own policy or fall through handler, implement your own version of that interface like this sample shown below:
public class MyMissingHandler : IMissingHandler
{
public Task Handle(Envelope envelope, IMessagingRoot root)
{
return root.Acknowledgements
.SendFailureAcknowledgement(envelope,"I don't know how to process this message");
}
}
Lastly, to register your own policy, just add it to the application IoC container like so:
public class ConfigureMissingHandlerApp : JasperOptions
{
public ConfigureMissingHandlerApp()
{
// Just add your type to the IoC container
Services.AddSingleton<IMissingHandler, MyMissingHandler>();
}
}
Do note that you can add multiple IMissingHandler
's in a single application and all of them will
be executed.