Ejemplo n.º 1
0
        public void CodeReceiver()
        {
            var conn    = connection.CreateConnection();
            var channel = conn.CreateModel();

            channel.QueueDeclare("gift-one", true, false, false, null);
            channel.QueueDeclare("gift-two", true, false, false, null);
            channel.QueueDeclare("gift-three", true, false, false, null);

            var consumerDiscount = new EventingBasicConsumer(channel);

            consumerDiscount.Received += (model, ea) =>
            {
                var body         = ea.Body;
                var message      = Encoding.UTF8.GetString(body);
                var deserialized = JsonConvert.DeserializeObject <Gift>(message);
                _logger.LogDebug("Received Discount Object:", deserialized.ToString());
                baseVoucherService.UpdateGiftVoucherAmount(deserialized.Code, deserialized.GiftBalance);
                _logger.LogDebug("Successful Update of Discount voucher:", deserialized.Code);
            };

            channel.BasicConsume(queue: "gift-one",
                                 autoAck: true,
                                 consumer: consumerDiscount);


            var consumerGift = new EventingBasicConsumer(channel);

            consumerGift.Received += (model, ea) =>
            {
                var body         = ea.Body;
                var message      = Encoding.UTF8.GetString(body);
                var deserialized = JsonConvert.DeserializeObject <Gift>(message);
                _logger.LogDebug("Received Gift Object{0} {1}", deserialized.Code, deserialized.GiftBalance);
                baseVoucherService.UpdateGiftVoucherAmount(deserialized.Code, deserialized.GiftBalance);
                _logger.LogDebug("Successful Update of GiftVoucher amount for voucher {0}", deserialized.Code);
            };
            channel.BasicConsume(queue: "gift-two",
                                 autoAck: true,
                                 consumer: consumerGift);

            var consumerValue = new EventingBasicConsumer(channel);

            consumerValue.Received += (model, ea) =>
            {
                var body         = ea.Body;
                var message      = Encoding.UTF8.GetString(body);
                var deserialized = JsonConvert.DeserializeObject <Value>(message);
                _logger.LogDebug("Received Value Object:", deserialized.Code, deserialized.ValueAmount);
                baseVoucherService.ActivateOrDeactivateVoucher(deserialized.Code);
                _logger.LogDebug("Successful Update of ValueVoucher:", deserialized.Code);
            };

            channel.BasicConsume(queue: "gift-three",
                                 autoAck: true,
                                 consumer: consumerValue);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> UpdateGiftVoucherAmount([FromRoute] string code, [FromQuery] long amount)
        {
            var patchedGift = await baseVoucherService.UpdateGiftVoucherAmount(code, amount);

            return(new OkObjectResult(patchedGift));
        }