コード例 #1
0
        public void SendRegisterOrderCommand(IRegisterOrderCommand registerOrderCommand)
        {
            channel.ExchangeDeclare(
                exchange: RabbitMqConstants.RegisterOrderExchange,
                type: ExchangeType.Direct);
            channel.QueueDeclare(
                queue: RabbitMqConstants.RegisterOrderQueue,
                durable: false,
                exclusive: false,
                autoDelete: false,
                arguments: null);
            channel.QueueBind(
                queue: RabbitMqConstants.RegisterOrderQueue,
                exchange: RabbitMqConstants.RegisterOrderExchange,
                routingKey: string.Empty);

            var command = JsonConvert.SerializeObject(registerOrderCommand);

            var messageProps = channel.CreateBasicProperties();

            messageProps.ContentType = RabbitMqConstants.JsonMimeType;

            var body = Encoding.UTF8.GetBytes(command);

            channel.BasicPublish(
                exchange: RabbitMqConstants.RegisterOrderExchange,
                routingKey: string.Empty,
                basicProperties: messageProps,
                body: body);
        }
コード例 #2
0
        public void Consume(IRegisterOrderCommand command)
        {
            //Store order registration and get Id
            var id = 12;

            Console.WriteLine($"Order with id {id} registered");

            //notify subscribers that a order is registered
            var orderRegisteredEvent =
                new OrderRegisteredEvent(command, id);
            //publish event
        }
コード例 #3
0
 public OrderRegisteredEvent(IRegisterOrderCommand command, int id)
 {
     this.OrderId        = id;
     this.PickupName     = command.PickupName;
     this.PickupAddress  = command.PickupAddress;
     this.PickupCity     = command.PickupCity;
     this.DeliverName    = command.DeliverName;
     this.DeliverAddress = command.DeliverAddress;
     this.DeliverCity    = command.DeliverCity;
     this.Weight         = command.Weight;
     this.Fragile        = command.Fragile;
     this.Oversized      = command.Oversized;
 }
コード例 #4
0
        private void Consume(IRegisterOrderCommand command)
        {
            //Store order registration and get Id
            var id = Guid.NewGuid();

            Console.WriteLine($"Order with id {id} registered");
            Console.WriteLine("Publishing order registered event");

            //notify subscribers that a order is registered
            var orderRegisteredEvent = new RabbitMqOrderRegisteredEvent(command, id);

            //publish event
            _rabbitMqManager.SendOrderRegisteredEvent(orderRegisteredEvent);
        }
コード例 #5
0
        public void SendRegisterOrderCommand(IRegisterOrderCommand command)
        {
            channel.ExchangeDeclare(RabbitMQConstants.RegisterOrderExchange, ExchangeType.Direct);
            channel.QueueDeclare(RabbitMQConstants.RegisterOrderServiceQueue, false, false, false, null);
            channel.QueueBind(RabbitMQConstants.RegisterOrderServiceQueue, RabbitMQConstants.RegisterOrderExchange, string.Empty);

            var serializedCommand = JsonConvert.SerializeObject(command);

            var messageProperties = channel.CreateBasicProperties();

            messageProperties.ContentType = RabbitMQConstants.JsonMimeType;

            channel.BasicPublish(RabbitMQConstants.RegisterOrderExchange, string.Empty, messageProperties, Encoding.UTF8.GetBytes(serializedCommand));
        }
コード例 #6
0
        private void Consumer(IRegisterOrderCommand command)
        {
            Random rnd = new Random();
            var    id  = rnd.Next(1, 13);

            Console.WriteLine($"Order with id: {id} registered");
            Console.WriteLine(command.ToString());

            var notificationOrderCommand = new NotificationOrderCommand()
            {
                OrderId = id
            };

            rabbitMQManager.SendNotificationOrderCommand(notificationOrderCommand);
        }
コード例 #7
0
ファイル: RabbitMqManager.cs プロジェクト: dborowski/WebStore
        public void SendRegisterOrderCommand(IRegisterOrderCommand command)
        {
            var serializedCommand = JsonConvert.SerializeObject(command);

            var messageProperties = _channel.CreateBasicProperties();

            messageProperties.ContentType =
                RabbitMqConstants.JsonMimeType;

            _channel.BasicPublish(
                exchange: RabbitMqConstants.RegisterOrderExchange,
                routingKey: "",
                basicProperties: messageProperties,
                body: Encoding.UTF8.GetBytes(serializedCommand));
        }
コード例 #8
0
 public OrderRegisteredEvent(IRegisterOrderCommand command, int id, Guid?correlationId = null)
 {
     if (correlationId.HasValue)
     {
         this.CorrelationId = correlationId.Value;
     }
     this.OrderId        = id;
     this.PickupName     = command.PickupName;
     this.PickupAddress  = command.PickupAddress;
     this.PickupCity     = command.PickupCity;
     this.DeliverName    = command.DeliverName;
     this.DeliverAddress = command.DeliverAddress;
     this.DeliverCity    = command.DeliverCity;
     this.Weight         = command.Weight;
     this.Fragile        = command.Fragile;
     this.Oversized      = command.Oversized;
 }
コード例 #9
0
        public void SendRegisterOrderCommand(IRegisterOrderCommand command)
        {
            _channel.ExchangeDeclare(
                exchange: RabbitMqConstants.RegisterOrderExchange,
                type: ExchangeType.Direct,
                durable: false,
                autoDelete: true);
            _channel.QueueDeclare(
                queue: RabbitMqConstants.RegisterOrderQueue,
                durable: false,
                exclusive: false,
                autoDelete: true,
                arguments: null);
            _channel.QueueBind(queue: RabbitMqConstants.RegisterOrderQueue,
                               exchange: RabbitMqConstants.RegisterOrderExchange,
                               routingKey: "register.order");

            _channel.ConfirmSelect();

            _channel.BasicAcks += (o, arg) =>
            {
                Console.WriteLine("======= BasicAcks");
                Console.WriteLine(o);
                Console.WriteLine(arg);
            };

            _channel.BasicNacks += (o, arg) =>
            {
                Console.WriteLine("======= BasicNAcks");
                Console.WriteLine(o);
                Console.WriteLine(arg);
            };

            var messageProperties = _channel.CreateBasicProperties();

            messageProperties.ContentType = RabbitMqConstants.JsonMimeType;

            var serializedCommand = JsonSerializer.Serialize(command);

            _channel.BasicPublish(RabbitMqConstants.RegisterOrderExchange,
                                  routingKey: "register.order",
                                  basicProperties: messageProperties,
                                  body: Encoding.UTF8.GetBytes(serializedCommand));
        }
コード例 #10
0
 public OrderRegisteredEvent(IRegisterOrderCommand command)
 {
     this.Id   = command.Id;
     this.Name = command.Name;
 }
コード例 #11
0
 public OrderRegisteredEvent(IRegisterOrderCommand command, int orderId)
 {
     this.command = command;
     this.orderId = orderId;
 }
コード例 #12
0
 public OrderRegistredEvent(IRegisterOrderCommand command, int id)
 {
     this.command = command;
     this.id      = id;
 }
コード例 #13
0
 public OrderRegisteredEvent(IRegisterOrderCommand command, int id)
 {
     _command = command;
     OrderId  = id;
 }
コード例 #14
0
 public RabbitMqOrderRegisteredEvent(IRegisterOrderCommand command, Guid id)
 {
     this.command = command;
     Id           = id;
 }