How to declare custom error exchange for each consumer in EasyNetQ?

左心房为你撑大大i 提交于 2019-12-10 14:08:07

问题


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

For example;

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

回答1:


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

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


来源:https://stackoverflow.com/questions/30547475/how-to-declare-custom-error-exchange-for-each-consumer-in-easynetq

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