错误消息发布到默认EasyNetQ_Default_Error_Queue时,我有四个使用者,是否有可能每个队列使用者都编写自己的错误交换
例如;
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");
最佳答案
从您提供的代码来看,您已经差不多了-您只需要适本地覆盖ErrorExchangeNamingConvention
和ErrorQueueNamingConvention
。
例如,这是一个方法,该方法将返回IBus
的实例,并覆盖这些约定以合并指定的使用者名称:
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;
}
关于c# - 如何在EasyNetQ中为每个使用者声明自定义错误交换?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30547475/