I am new to EasyNetQ and RabbitMQ.Unfortunately I am having problem with consuming messages and I am not sure if its because I am doing the Publish wrong or either my consuming is not correct. I can see by publishing, it does send to queue and consuming it does take it off from the queue. However when message is returned I get null :S I am using IAdvancedBus
Code Snippet for Publishing:
public void send(RegistrationCreatedEvent obj )
{
MessageBus.Publish(Exchange, RoutingKey, true, new Message<RegistrationCreatedEvent>(obj));
}
Code Snippet for Consuming:
public void Receive()
{
MessageBus.Consume(Queue, (messageBody, properties, info) => Task.Factory.StartNew(() =>
{
var stringMessage = Encoding.Default.GetString(messageBody);
json = JsonConvert.DeserializeObject<RegistrationCreatedEvent>(stringMessage);
Console.WriteLine($"Message Received: {json}");
}));
}
Could you tell us which variable is null? If
messageBody
is already null you may have a problem in publishing. Then I would recommend that you stop your consumer, send a message to the queue and go have a look at the messages with the management plugin https://www.rabbitmq.com/management.htmlAnd since you want your message deserialized anyway i would recommend to use the built in messageSerializer instead of doing it by yourself. Would look something like this: