Skip to content

Instantly share code, notes, and snippets.

@fatihdumanli
Created November 3, 2020 11:42
Show Gist options
  • Save fatihdumanli/03f04d843374671e96385a0b5063c65e to your computer and use it in GitHub Desktop.
Save fatihdumanli/03f04d843374671e96385a0b5063c65e to your computer and use it in GitHub Desktop.
Setting the endpoint for receiving messages
public void StartConsuming()
{
consumerChannel = connection.CreateModel();
consumerChannel.ExchangeDeclare(COMMAND_EXCHANGE_NAME, ExchangeType.Direct);
consumerChannel.ExchangeDeclare(EVENT_EXCHANGE_NAME, ExchangeType.Fanout);
var queue = consumerChannel.QueueDeclare(queue: queueName);
consumerChannel.QueueBind(queue, COMMAND_EXCHANGE_NAME, routingKey: queueName);
consumerChannel.QueueBind(queue, EVENT_EXCHANGE_NAME, routingKey: queueName);
var consumer = new EventingBasicConsumer(consumerChannel);
consumerChannel.BasicConsume(queue: queueName, autoAck: true, consumer: consumer);
consumer.Received += (model, ea) => {
var messageBody = ea.Body.ToArray().GetPayloadString();
var args = JsonConvert.DeserializeObject<MessageReceivedEventArgs>(messageBody);
MessageReceived.Invoke(args);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment