Example #1
0
 /// <summary>
 /// Subscribing event from publisher.
 /// </summary>
 /// <param name="event">This event comming from Transaction Queue</param>
 /// <returns></returns>
 private void Handle(ProcessTransactionQueueIntegrationEvent @event)
 {
     try
     {
         _mediator.Execute(@event);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.ToString());
     }
 }
Example #2
0
        private void PublishDeviceCommunicationRequest(TransactionQueueModel transactionQueue, Dictionary <string, string> headers)
        {
            var eventMessage = new ProcessTransactionQueueIntegrationEvent()
            {
                TransactionData = new TransactionData
                {
                    Quantity = transactionQueue.Quantity.Value,
                    Type     = transactionQueue.Type,
                    Devices  = transactionQueue.Devices.ToList()
                },
                Headers = headers
            };

            _eventBus.Publish(_configuration.KafkaDeviceTopic, eventMessage, headers);
            _logger.LogInformation(string.Format(Constants.LoggingMessage.DataPublishedDeviceCommunication, JsonConvert.SerializeObject(eventMessage)));
        }
        public void HandleExecuteSuccess()
        {
            ProcessTransactionQueueEventHandler     processTransactionQueueEventHandler     = new ProcessTransactionQueueEventHandler(_mediator.Object, _logger.Object);
            ProcessTransactionQueueIntegrationEvent processTransactionQueueIntegrationEvent = new ProcessTransactionQueueIntegrationEvent();
            var device = new Device {
                DeviceId = 1234, Type = "Carousel", Attribute = new DeviceAttribute(), StorageSpaces = new List <StorageSpace>()
            };
            var listDevices = new List <Device>(); listDevices.Add(device);

            processTransactionQueueIntegrationEvent.TransactionData = new TransactionData {
                Devices = listDevices, Quantity = 1, Type = "R"
            };
            processTransactionQueueIntegrationEvent.Headers = new Dictionary <string, string>();
            var result = processTransactionQueueEventHandler.Handle(processTransactionQueueIntegrationEvent);

            Assert.NotNull(result);
        }
Example #4
0
        public void ProcessTransactionMediatorExecuteSuccess()
        {
            //Arrange
            ProcessTransactionQueueIntegrationEvent transQueueEvent = new ProcessTransactionQueueIntegrationEvent();
            var device = new Device()
            {
                DeviceId = 123, Type = "Carousel", Attribute = new DeviceAttribute(), StorageSpaces = new List <StorageSpace>()
            };
            var listDevices = new List <Device>(); listDevices.Add(device);

            transQueueEvent.TransactionData = new TransactionData {
                Devices = listDevices, Quantity = 1, Type = "R"
            };
            ProcessTransactionMediator processTransactionMediator = new ProcessTransactionMediator(_logger.Object, _carouselProcess.Object);

            //Act
            processTransactionMediator.Execute(transQueueEvent);

            //Assert
            Assert.True(true);
        }
Example #5
0
        public IActionResult PublishMessageEvent(ProcessTransactionQueueIntegrationEvent messageEvent)
        {
            try
            {
                _logger.LogInformation("Demo Data recieved from postman or swagger in device communication API");
                var headers = Request.Headers.ToDictionary <KeyValuePair <string, StringValues>, string, string>(item => item.Key, item => item.Value);

                var kafkaSettings = _configuration.GetSection("MessageBusTopics").GetChildren()
                                    .Select(item => new KeyValuePair <string, string>(item.Key, item.Value))
                                    .ToDictionary(x => x.Key, x => x.Value);

                _eventBus.Publish(kafkaSettings["KafkaTopic"], messageEvent, headers);
                //Handle(messageEvent);
                _logger.LogInformation("Demo Data published from device communication API");
                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }