0

I'm using Rabbitmq Queue solution and i have 4 queues and one consumer. i want my consumer consume all of these queues and provide separate Handler for each one.

I googled this and found that Rabbitmq and EasyNetQ (.Net Client for RabbitMQ), provides this feature with The Advanced API (this link and This link)

The sample code provided in this articles to define multiple handler for a consumer :

bus.Advanced.Consume(queue, x => 
x.Add<MyMessage>((message, info) => { Console.WriteLine("Got MyMessage {0}", message.Body.Text); countdownEvent.Signal(); }) 
.Add<MyOtherMessage>((message, info) => { Console.WriteLine("Got MyOtherMessage {0}", message.Body.Text); countdownEvent.Signal(); }) 
);

My Problem : So when i try to use this example, the Add<> method is unknown. What is The problem? and what i should do to make this method available?

my code's using part :

using RabbitMQ;
using EasyNetQ;
using EasyNetQ.Consumer;

My Code :

using (var bus = RabbitHutch.CreateBus("host=localhost;prefetchcount=100"))
            {
                var queue = bus.Advanced.QueueDeclare("QueueMessageTypes.VehicleDeviceChangeMessage:QueueMessageTypes_VehicleDeviceChangeMsg");

                bus.Advanced.Consume(queue, x => x
                        .Add<PositionMessage>((message, info) =>
                        {
                            Console.WriteLine("Got MyMessage {0}", message.Body.Text);
                        })
                        .Add<VehicleDeviceChangeMessage>((message, info) =>
                        {
                            Console.WriteLine("Got MyOtherMessage {0}", message.Body.Text);
                        })
                    );
            }

I think i should use a namespace or a class to use Add<> method. may it's a extension method that i should find and add related class from a library.

Mike Argyriou
  • 1,250
  • 2
  • 18
  • 30
Javad Norouzi
  • 327
  • 4
  • 11

1 Answers1

0

After some search and test of many methods, i wrote the complete syntax of my code and ignored compiler error hint, and C# Compiler accepted Add<> method. after that it knows the Add<> method without adding any using part or other additional work.

but i have another problem that i think i should post it in separate question : I added handlers but they don't act any action on messages. the messages remain in queue.

my finall code that compiler accepts it (but doe not work):

using (var advancedBus = RabbitHutch.CreateBus("host=localhost;prefetchcount=100").Advanced)
            {
                var queue = advancedBus.QueueDeclare("MyQueue");

                advancedBus.Consume(queue, x => x
                        .Add<MessageType1>((message, info) =>
                                    {
                                        Console.WriteLine("MessageType1 Body : " + message.Body.Body);
                                        );
                                    })
                        .Add<MessageType2>((message, info) => 
                            {
                                Console.WriteLine(" MessageType2 Body: " + message.Body.Body);
                               }
                        )
                        .ThrowOnNoMatchingHandler = false
                      );
            }
Javad Norouzi
  • 327
  • 4
  • 11