public void PublishRegisteredNotification(IOrderRegistered order)
        {
            channel.ExchangeDeclare(
                exchange: RabbitMqConstants.OrderRegisteredExchange,
                type: ExchangeType.Fanout);

            channel.QueueDeclare(
                queue: RabbitMqConstants.OrderRegisteredNotificationQueue,
                durable: false, exclusive: false,
                autoDelete: false, arguments: null);

            channel.QueueBind(
                queue: RabbitMqConstants.OrderRegisteredNotificationQueue,
                exchange: RabbitMqConstants.OrderRegisteredExchange,
                routingKey: "");

            var serializedOrder = JsonConvert.SerializeObject(order);

            var messageProperties = channel.CreateBasicProperties();

            messageProperties.ContentType = RabbitMqConstants.JsonMimeType;

            channel.BasicPublish(
                exchange: RabbitMqConstants.OrderRegisteredExchange,
                routingKey: "",
                basicProperties: messageProperties,
                body: Encoding.UTF8.GetBytes(serializedOrder));
        }
示例#2
0
        public void SendOrderRegisteredEvent(IOrderRegistered command)
        {
            channel.ExchangeDeclare(
                exchange: RabbitMqConstants.GetOrderRegisteredExchange(),
                type: ExchangeType.Fanout);

            var serializedCommand = JsonConvert.SerializeObject(command);

            var messageProperties = channel.CreateBasicProperties();

            messageProperties.ContentType = RabbitMqConstants.JsonMimeType;

            channel.BasicPublish(
                exchange: RabbitMqConstants.GetOrderRegisteredExchange(),
                routingKey: "",
                basicProperties: messageProperties,
                body: Encoding.UTF8.GetBytes(serializedCommand));
        }
示例#3
0
 public void Consume(IOrderRegistered registered)
 {
     //Send notification to user
     Console.WriteLine($"Customer notification sent: Order id {registered.OrderId} registered");
 }