如何在EasyNetQ中为每个使用者声明自定义错误交换? [英] How to declare custom error exchange for each consumer in EasyNetQ?

查看:147
本文介绍了如何在EasyNetQ中为每个使用者声明自定义错误交换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当错误发生时,我有四个使用者,将消息发布到默认的EasyNetQ_Default_Error_Queue,是否每个队列使用者都可以编写自己的错误交换信息

I have four consumer when error occured message publishing to default EasyNetQ_Default_Error_Queue is it possible to each queue consumer write own error exchange

例如;

Queue Name : A    ErrorExchange :A_ErrorExchange
Queue Name : B    ErrorExchange :B_ErrorExchange


bus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info => "A_DeadLetter");

bus.Advanced.Conventions.ErrorExchangeNamingConvention = new ErrorExchangeNameConvention(info2 => "B_DeadLetter");

推荐答案

从您提供的代码来看,您似乎已经差不多了-您只需要适当地覆盖ErrorExchangeNamingConventionErrorQueueNamingConvention即可.

From the code you've provided, it looks like you're almost there -- you just need to override ErrorExchangeNamingConvention and ErrorQueueNamingConvention appropriately.

作为示例,这是一个方法,该方法将返回IBus的实例,并覆盖这些约定以合并指定的使用者名称:

As an example, here's a method that will return an instance of IBus with these conventions overridden to incorporate the specified consumer name:

public IBus CreateBus(string connectionString, string consumerName) 
{
    var bus = RabbitHutch.CreateBus(connectionString);

    // Modify the following to create your error exchange name appropriately
    bus.Advanced.Container.Resolve<IConventions>().ErrorExchangeNamingConvention = 
        info => consumerName + "_ErrorExchange";

    // Modify the following to create your error queue name appropriately
    bus.Advanced.Container.Resolve<IConventions>().ErrorQueueNamingConvention = 
        () => consumerName + "_ErrorQueue";

    return bus;
}

这篇关于如何在EasyNetQ中为每个使用者声明自定义错误交换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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