我有四个消费者,当错误发生时消息发布到默认值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");
答案 0 :(得分:3)
根据您提供的代码,您似乎就在那里 - 您只需要适当地覆盖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;
}