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

1

6

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");
Cecilycecity answered 30/5, 2015 at 14:43 Comment(0)
S
7

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;
}
Syllabus answered 5/6, 2015 at 13:32 Comment(1)
Unfortunately, as per EasyNetQ 6.3.1, ErrorExchangeNamingConvention and ErrorQueueNamingConvention are both changed to read-only :( and the naming convention has to be injected during bus creation.Shalom

© 2022 - 2024 — McMap. All rights reserved.