public async Task <ActionResult <OrderModel> > ChangeOrderStatus(int orderId, OrderStatus status)
        {
            _logger.LogInformation("Start to setting order with OrderId {OrderId} status to \"{OrderStatus}\"",
                                   orderId, status.ToString());

            try
            {
                var order = await _orderRepository.SetOrderStatusAsync(orderId, status);

                _logger.LogInformation("Order with OrderId {OrderId} status is successfuly set to \"{OrderStatus}\"",
                                       orderId, status.ToString());

                var changeStatusDto = _mapper.Map <ChangeStatusDto>(order);
                _rabbitManager.Publish(changeStatusDto, "OrderService_ChangeOrderStatusExchange", ExchangeType.Fanout, "ChangeOrderStatus");

                return(_mapper.Map <OrderModel>(order));
            }
            catch (InvalidOperationException e)
            {
                _logger.LogInformation("Fail to set order with OrderId {OrderId} status to \"{OrderStatus}\"",
                                       orderId, status.ToString());

                return(BadRequest(e.Message));
            }
        }
Пример #2
0
        public async Task <ActionResult <BasketItemModel> > Create(BasketItemModel basketItemModel)
        {
            var basketItem = new BasketItem
            {
                Name        = basketItemModel.Name,
                Amount      = basketItemModel.Amount,
                Hint        = basketItemModel.Hint,
                Description = basketItemModel.Description,
                UserId      = User.GetLoggedInUserId(),
                DateCreated = basketItemModel.DateCreated,
                ItemType    = basketItemModel.ItemType
            };

            await basketItemRepository.Create(basketItem);

            var result = MapToModel(basketItem);

            manager.Publish(
                message: result,
                exchangeName: "base.exchange.topic",
                exchangeType: ExchangeType.Topic,
                routeKey: "notifications.basket.add"
                );

            return(new ObjectResult(result));
        }
 public Result Send(Message message)
 {
     _manager.Publish(message, "to_messenger");
     return(new Result {
         Succes = true
     });
 }
Пример #4
0
        private async void HandleMessage(string content)
        {
            using (var scope = _scopeFactory.CreateScope())
            {
                try
                {
                    var orderRepository = scope.ServiceProvider.GetRequiredService <IOrderRepository>();
                    var payForOrderDto  = JsonConvert.DeserializeObject <PayForOrderDto>(content);
                    _logger.LogInformation("Start updating status and payment info for order with OrderId {OrderId}.",
                                           payForOrderDto.OrderId);
                    var order = await orderRepository.PayForOrderAsync(
                        payForOrderDto.OrderId,
                        payForOrderDto.PaymentId,
                        payForOrderDto.Status);

                    var changeStatusDto = _mapper.Map <ChangeStatusDto>(order);
                    _rabbitManager.Publish(changeStatusDto, "OrderService_ChangeOrderStatusExchange", ExchangeType.Fanout, "OrderStatusChanged");

                    _logger.LogInformation("Status and payment info for order with OrderId {OrderId} has been successfuly updated.",
                                           payForOrderDto.OrderId);
                }
                catch (Exception e)
                {
                    //_logger.LogInformation("Failed to update status and payment info for order with OrderId {OrderId}.",
                    //    payForOrderDto.OrderId);
                }
            }
        }
Пример #5
0
        public IActionResult Post(Person person)
        {
            Console.WriteLine("message: ");
            var indexResponse = client.IndexDocument(person);

            manager.Publish(person, "Boards_Exchange", "topic", "kibin");
            return(Ok(indexResponse));
        }
Пример #6
0
 public async Task Write(Reservation reservation)
 {
     Manager
     .Publish(
         reservation,
         "",
         "direct",
         "reservations");
 }
Пример #7
0
        public async Task <IActionResult> GetAll()
        {
            //List<SinhVien> sv = _context.SinhVien.ToList();
            //return Ok(sv);
            var sv = this._context.SinhVien.Where(x => x.MaSv == "A10");

            _manager.Publish(sv, "demo.exchange.topic.dotnetcore", "topic", "*.queue.durable.dotnetcore.#");
            return(Ok(sv));
        }
Пример #8
0
        public Task Execute(IJobExecutionContext context)
        {
            //add to rabbitMq
            var person = new Person("hatef", "mahdizadeh", 31);

            _rabbitManager.Publish <Person>(person, "direct_logs", "direct", "");
            Console.WriteLine(person.ToJson());
            return(Task.CompletedTask);
        }
Пример #9
0
 public ActionResult <Order> Post([FromBody] Order order)
 {
     order.OrderId = _ordersModel.AddOrder(order);
     _rabbitManager.Publish(
         order, _brokerConfigInfo.ExchangeName, "topic", _brokerConfigInfo.RouteKey);
     return(CreatedAtAction(
                nameof(GetById),
                new { id = order.OrderId },
                order));
 }
Пример #10
0
        public ActionResult <IEnumerable <string> > Get()
        {
            var num = new System.Random().Next(9000);

            _manager.Publish(new
            {
                field1 = $"PocRabbitMQ-{num}",
                field2 = $"Mineiro-{num}"
            }, "demo.exchange.topic.dotnetcore", "topic", "*.queue.durable.dotnetcore.#");

            return(new string[] { "value1", "value2" });
        }
Пример #11
0
        //забираем сообщения с мессенджеров
        private void GetMessages()
        {
            var message = new Message {
                ChatId = Guid.NewGuid().ToString(), Text = Guid.NewGuid().ToString(), TimeStamp = DateTime.Now, ClientInfo = new ClientInfo()
                {
                    Phone = "+7" + (new Random().Next(1000000, 9999999)) + (new Random().Next(100, 999))
                }
            };

            _manager.Publish(message, "from_messenger");
            Debug.WriteLine($"Publish from_messenger: { JsonConvert.SerializeObject(message) } ");
        }
Пример #12
0
        public async Task <IActionResult> CreateUser([FromBody] UserDto user)
        {
            if (user == null)
            {
                return(BadRequest());
            }

            await _userRepository.Add(new User()
            {
                Name      = user.Name,
                BirthDate = user.BirthDate,
                Email     = user.Email,
                Hobbies   = user.Hobbies,
            });

            _rabbitManager.Publish(new
            {
                Message = "User Created",
                Name    = $"{user.Name}"
            }, "", "", "bg.queue.log");

            return(Ok());
        }
        public async Task <IActionResult> Post(string message)
        {
            try
            {
                var @event = new Event(Guid.NewGuid().ToString(), message);
                await _manager.Publish(@event);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Пример #14
0
        public ActionResult <IEnumerable <string> > Get()
        {
            // other opreation

            // if above operation succeed, publish a message to RabbitMQ

            var num = new System.Random().Next(9000);

            // publish message
            _manager.Publish(new
            {
                field1 = $"Hello-{num}",
                field2 = $"rabbit-{num}"
            }, "demo.exchange.topic.dotnetcore", "topic", "*.queue.durable.dotnetcore.#");

            return(new string[] { "value1", "value2" });
        }
        public IEnumerable <WeatherForecast> Get()
        {
            var rng = new Random();
            IEnumerable <WeatherForecast> result = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            })
                                                   .ToArray();

            _logger.LogInformation("Returning weather information @ {date}", DateTime.UtcNow);
            _logger.LogInformation("First Weather Forecast @  {forecast}", result.First());
            try
            {
                _manager.Publish(result.First(), "web-api.service", "topic", "WebApi.WeatherForecast.GET");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            return(result);
        }
Пример #16
0
 public void SendReservationForProcessing(GetReservationItemResponse reservation)
 {
     Manager.Publish(reservation, "", "direct", "reservations");
 }
Пример #17
0
 public IActionResult PostMessage([FromBody] Product body)
 {
     _manager.Publish(body, "demo.exchange.dotnetcore", "product-queue", "queue.durable.dotnetcore");
     return(Ok("Message Published Successfully..!"));
 }
Пример #18
0
 public async Task SendMessage(string p_Message)
 {
     m_Manager.Publish(p_Message, "server.exchange", "topic", "server.queue.*");
 }
        public IActionResult Post([FromServices] IRabbitManager p_Manager, [FromForm] FormObject p_Form)
        {
            p_Manager.Publish(p_Form.Text, "server.exchange", "topic", "server.queue.*");

            return(Ok());
        }
Пример #20
0
 public Task AddWorkAsync(BookReservation reservation)
 {
     // Todo: What should our "Plan B" be?
     _manager.Publish(reservation, "", "direct", "reservations");
     return(Task.CompletedTask);
 }
Пример #21
0
        public async Task <ActionResult <OrderModel> > PayForOrderAsync(int orderId, UserDetailsModel userDetails)
        {
            try
            {
                _logger.LogInformation("{Username} has started payment for the order with OrderId {OrderId}.",
                                       userDetails.Username, orderId);

                if (userDetails.CardAuthorizationInfo.ToLower() != "authorized" &&
                    userDetails.CardAuthorizationInfo.ToLower() != "unauthorized")
                {
                    throw new ArgumentException("CardAuthorizationInfo is not valid.");
                }


                var orderRequestDto = new OrderRequestDto {
                    OrderId = orderId
                };
                _rpcClient.Open();
                var order = _rpcClient.Call(orderRequestDto);
                _rpcClient.Close();


                if (order.OrderId == 0)
                {
                    throw new ArgumentException("No order with such id.");
                }

                if (userDetails.Username != order.Username)
                {
                    throw new ArgumentException("Usernames in order and user details should be equal.");
                }

                if (order.Status.ToLower() != "collecting")
                {
                    throw new InvalidOperationException("Order status should be \"Collecting\".");
                }

                switch (userDetails.CardAuthorizationInfo.ToLower())
                {
                case "authorized":
                    order.PaymentId = DateTime.Now.Ticks;
                    order.Status    = "Paid";
                    break;

                case "unauthorized":
                    order.PaymentId = DateTime.Now.Ticks;
                    order.Status    = "Failed";
                    break;
                }

                var payment = new Payment
                {
                    PaymentId = order.PaymentId.Value,
                    OrderId   = order.OrderId,
                    Username  = order.Username,
                    TotalCost = order.TotalCost,
                    IsPassed  = order.Status == "Paid" ? true : false
                };

                await _paymentRepository.AddPaymentAsync(payment);

                var payForOrderDto = _mapper.Map <PayForOrderDto>(order);

                _rabbitManager.Publish(payForOrderDto, "PaymentService_OrderExchange", ExchangeType.Direct, "PayForOrder");

                _logger.LogInformation("{Username} has finished payment for the order with OrderId {OrderId} with status {Status}.",
                                       order.Username, order.OrderId, order.Status);

                return(order);
            }
            catch (TimeoutException e)
            {
                _logger.LogInformation("{Username} has failed to perform payment for the order with OrderId {OrderId}.",
                                       userDetails.Username, orderId);

                return(StatusCode(408, e.Message));
            }
            catch (Exception e)
            {
                _logger.LogInformation("{Username} has failed to perform payment for the order with OrderId {OrderId}.",
                                       userDetails.Username, orderId);

                return(BadRequest(e.Message));
            }
        }
Пример #22
0
 public Task LogOrder(GetReservationResponse request)
 {
     _manager.Publish(request, "", "direct", "reservations");
     return(Task.CompletedTask);
 }
 public Task ProcessReservation(Reservation reservation)
 {
     _manager.Publish(reservation, "", "direct", "reservations");
     return(Task.CompletedTask);
 }
Пример #24
0
 public string Get(int id)
 {
     _rabbitClient.Publish <string>(id.ToString(), "", "hello");
     return($"{id} sent to rabbitmq...");
 }
 public void SendReservation(ReservationItem response)
 {
     Manager.Publish(response, "", "direct", "reservations");
 }
Пример #26
0
 public void SendForProcessing(GetReservationItemResponse response)
 {
     Manager.Publish(response, "", "direct", "reservationQueue");
 }
 public void SendReservationForProcessing(Reservation reservation)
 {
     Manager.Publish(reservation, "", "direct", "reservations");
 }
Пример #28
0
 public IActionResult GetDistance(GeoPoints model)
 {
     // publish message
     _manager.Publish(model, "RabbitMQ", "fanout", "RabbitMQ");
     return(Ok("Distance inserted, you can check GetAllDistances"));
 }