How to Nak a ServiceStack RabbitMQ message within the RegisterHandler?

时光怂恿深爱的人放手 提交于 2019-12-08 09:36:41

问题


I'd like to be able to requeue a message from within my Service Endpoint that has been wired up through the RegisterHandler method of RabbitMQ Server. e.g.

mqServer.RegisterHandler<OutboundILeadPhone>(m =>
{
    var db = container.Resolve<IFrontEndRepository>();
    db.SaveMessage(m as Message);
    return ServiceController.ExecuteMessage(m);
}, noOfThreads: 1);

or here.

public object Post(OutboundILeadPhone request)
{
    throw new OutBoundAgentNotFoundException(); // added after mythz posted his first response
}

I don't see any examples how this is accomplished, so I'm starting to believe that it may not be possible with the ServiceStack abstraction. On the other hand, this looks promising.

Thank you, Stephen

Update

Throwing an exception in the Service does nak it, but then the message is sent to the OutboundILeadPhone.dlq which is normal ServiceStack behavior. Guess what I'm looking for is a way for the message to stay in the OutboundILeadPhone.inq queue.


回答1:


Throwing an exception in your Service will automatically Nak the message. This default exception handling behavior can also be overridden with RabbitMqServer's RegisterHandler API that takes an Exception callback, i.e:

void RegisterHandler<T>(
    Func<IMessage<T>, object> processMessageFn, 
    Action<IMessage<T>, Exception> processExceptionEx);

void RegisterHandler<T>(
    Func<IMessage<T>, object> processMessageFn, 
    Action<IMessage<T>, Exception> processExceptionEx, 
    int noOfThreads)


来源:https://stackoverflow.com/questions/27519209/how-to-nak-a-servicestack-rabbitmq-message-within-the-registerhandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!