Created
November 3, 2020 11:42
-
-
Save fatihdumanli/03f04d843374671e96385a0b5063c65e to your computer and use it in GitHub Desktop.
Setting the endpoint for receiving messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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