Exemplo n.º 1
0
        static void Main(string[] args)
        {
            RabbitMQService.Start(ConfigHelper.RabbitMQURI);

            var consumer = new RabbitMQConsumer(
                ConfigHelper.SubQueueNames,
                new PubSubDispatcher <RabbitMQEventStream>(AutofacConfig.Container),
                ConfigHelper.QueueId);

            consumer.Start();

            Parallel.ForEach(Enumerable.Range(0, ConfigHelper.ProducerBatchCount), (index) =>
            {
                RabbitMQProducer.Publish(
                    ConfigHelper.QueueId,
                    new PressureTestContentEvent()
                {
                    Content        = $"{DateTime.Now.ToString("yyyyMMdd HH:mm:ss.fff")}-{index}",
                    CreateDateTime = DateTime.Now
                });
            });

            Console.Read();

            RabbitMQService.Stop();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CheckoutModel model)
        {
            var shoppingCart = await _shoppingCartService.GetShoppingCart(model.CustomerId, ShoppingCartType.ShoppingCart);

            if (shoppingCart == null)
            {
                return(BadRequest(new ErrorResult()));
            }

            var checkoutEvent = model.ModelToEvent <CheckoutEvent>();

            // get total price of shopping cart
            checkoutEvent.TotalPrice = shoppingCart.ShoppingCartItems.Sum(x => x.TotalPriceInclTax);

            var shoppingCartRemoved = await _shoppingCartService.DeleteShoppingCart(model.CustomerId, ShoppingCartType.ShoppingCart);

            if (!shoppingCartRemoved)
            {
                return(BadRequest(new ErrorResult()));
            }

            //send checkout event to rabbitmq
            _rabbitMQProducer.Publish(CheckoutEventDefaults.BasketCheckoutQueue, checkoutEvent);

            return(Ok(new SuccessResult()));
        }