Esempio n. 1
0
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var incomingMessage = message.GetBody <PostAlertMessage>();
            var alert           = _autoMapperService.MapObject <Alert>(incomingMessage.AlertDto);
            await _alertRepository.SaveAlert(alert, incomingMessage.TransportationId);

            var payload = new PostAlertResultMessage();

            await _serviceBusCommunicationService.SendBrokeredMessage(new BrokeredMessage(payload)
            {
                SessionId = message.SessionId
            }, "Processed-Post-Alert-Queue");
        }
Esempio n. 2
0
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var userDto = message.GetBody <UserDto>();
            var user    = _autoMapperService.MapObject <User>(userDto);
            await _userRepository.AddUser(user);

            WriteLog($"Handling queue message {message.MessageId}");
            var payload = new AddUserResultMessage();

            await _serviceBusCommunicationService.SendBrokeredMessage(new BrokeredMessage(payload)
            {
                SessionId = message.SessionId
            }, "Processed-Post-User-Queue");
        }
Esempio n. 3
0
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var userId         = message.GetBody <Guid>();
            var userViolations = await _violationService.GetUserViolations(userId);

            var violationDtos = _autoMapperService.MapObject <List <ViolationDto> >(userViolations.ToList());
            var payload       = new GetUserViolationListResultMessage
            {
                Violations = violationDtos
            };
            await _serviceBusCommunicationService.SendBrokeredMessage(new BrokeredMessage(payload)
            {
                SessionId = message.SessionId
            }, "Processed-Get-User-Violation-List-Queue");
        }
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var transportationId = message.GetBody <Guid>();
            var alerts           = await _alertRepository.GetTransportationAlerts(transportationId);

            var alertResultDtos = _autoMapperService.MapObject <IEnumerable <AlertResultDto> >(alerts);
            var payload         = new GetTransportationAlertListResultMessage {
                Alerts = alertResultDtos
            };

            await _serviceBusCommunicationService.SendBrokeredMessage(new BrokeredMessage(payload)
            {
                SessionId = message.SessionId
            }, "Processed-Get-Transportation-Alert-List-Queue");
        }
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var users = await _userRepository.GetUsers();

            var userDtoList = _autoMapperService.MapObject <List <UserDto> >(users);

            WriteLog($"Handling queue message {message.MessageId}");
            var payload = new GetUsersResultMessage
            {
                UserDtos = userDtoList
            };

            await _serviceBusCommunicationService.SendBrokeredMessage(new BrokeredMessage(payload)
            {
                SessionId = message.SessionId
            }, "Processed-Get-Users-Queue");
        }
        protected override async Task ReceiveMessageImplAsync(
            BrokeredMessage message,
            MessageSession session,
            CancellationToken cancellationToken)
        {
            var capturedLocationsMessage = message.GetBody <PostCapturedLocationsMessage>();
            var capturedLocations        =
                _autoMapperService.MapObject <List <CapturedLocation> >(capturedLocationsMessage
                                                                        .CapturedLocations);

            if (capturedLocations == null)
            {
                WriteLog(
                    $"No locations in message payload for transportationId: {capturedLocationsMessage.TransportationId.ToString()}");
                return;
            }

            _capturedLocationService.ProcessCapturedLocations(capturedLocationsMessage.TransportationId,
                                                              capturedLocations);
        }
        public async Task <ActionResult> Post(
            [FromRoute] Guid transportationId,
            [FromBody] IEnumerable <CapturedLocation> capturedLocations)
        {
            var capturedLocationDtos =
                _autoMapperService.MapObject <IEnumerable <CapturedLocationDto> >(capturedLocations);
            var postMessage = new PostCapturedLocationsMessage
            {
                TransportationId  = transportationId,
                CapturedLocations = capturedLocationDtos
            };
            var sessionId = Guid.NewGuid().ToString();
            var message   = new BrokeredMessage(postMessage)
            {
                SessionId = sessionId
            };
            const string queueName = "Incoming-Post-Captured-Locations-Queue";
            // Processed queue currently not in use because there is no need to wait for a response from the microservice. The response can be delivered back, that message was sent successfully.
            //const string processsedQueueName = "Processed-Post-Captured-Locations-Queue";
            await _messageBrokerService.SendBrokeredMessage(message, queueName);

            return(NoContent());
        }