PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 19, 2022

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

 September 19, 2022     c#, consumer, easynetq, rabbitmq     No comments   

Issue

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

Solution

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


Answered By - Donut
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing