Exemplo n.º 1
0
        public void SendUserRegisteredEvent(IUserRegisteredEvent command)
        {
            // exchange type: fanout - send a message to multiple queues

            channel.ExchangeDeclare(
                exchange: Constants.UserRegisteredExchange,
                type: ExchangeType.Fanout);

            channel.QueueDeclare(
                queue: Constants.UserRegisteredNotificationQueue,
                durable: false, exclusive: false,
                autoDelete: false, arguments: null);

            channel.QueueBind(
                queue: Constants.UserRegisteredNotificationQueue,
                exchange: Constants.UserRegisteredExchange,
                routingKey: "");

            var serializedCommand = JsonConvert.SerializeObject(command);

            var messageProperties = channel.CreateBasicProperties();

            messageProperties.CorrelationId = Guid.NewGuid().ToString();

            messageProperties.ContentType = Constants.JsonMimeType;

            channel.BasicPublish(
                exchange: Constants.UserRegisteredExchange,
                routingKey: "",
                basicProperties: messageProperties,
                body: Encoding.UTF8.GetBytes(serializedCommand));
        }
Exemplo n.º 2
0
 public void Consume(IUserRegisteredEvent registeredEvent)
 {
     // Send notification to user
     Console.WriteLine($"Customer notification sent: UserId {registeredEvent.UserId} registered");
 }