如何在 RegisterHandler 中获取 ServiceStack RabbitMQ 消息? [英] How to Nak a ServiceStack RabbitMQ message within the RegisterHandler?

查看:39
本文介绍了如何在 RegisterHandler 中获取 ServiceStack RabbitMQ 消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从我的服务端点内重新排队通过 RabbitMQ 服务器的 RegisterHandler 方法连接的消息.例如

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);

或这里.

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

我没有看到任何示例说明这是如何实现的,因此我开始相信 ServiceStack 抽象可能无法实现.另一方面,这个看起来很有希望.

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.

谢谢你,斯蒂芬

更新

在服务中抛出一个异常并没有解决它,但随后消息被发送到 OutboundILeadPhone.dlq,这是正常的 ServiceStack 行为.猜猜我在寻找什么让消息留在 OutboundILeadPhone.inq 队列中的方法.

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.

推荐答案

在您的 Service 中抛出异常将 自动取消消息.这个默认的异常处理行为也可以被 RabbitMqServer 的 RegisterHandler API 覆盖,它接受一个 Exception 回调,即:

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)

这篇关于如何在 RegisterHandler 中获取 ServiceStack RabbitMQ 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆