public async Task Consume(ConsumeContext <IResponseTagExistingEventClustersRequested> context) { try { _logger.LogDebug($"EventClusterAssignResponseRequestedConsumer: Retrieved message from response '{context.Message.ResponseId}'."); if (context.Message.ResponseGeolocation == null) { _logger.LogDebug($"EventClusterAssignResponseRequestedConsumer: The response does not have a location."); return; } var eventClusterIds = await _eventClusterRestService.GetClustersInRadius(new EventClusterGeolocationModel() { Radius = context.Message.Radius, ResponseGeolocationPointLocation = context.Message.ResponseGeolocation }); if (eventClusterIds != null) { if (eventClusterIds.ToList().Count == 0) { _logger.LogDebug($"EventClusterAssignResponseRequestedConsumer: No Event Clusters found."); return; } _logger.LogDebug($"EventClusterAssignResponseRequestedConsumer: Event Cluster Ids retrieved."); //Add event cluster Ids to response var result = await _responseRestService.AddEventClusterIdsToResponse(new ResponseEventClustersUpdateModel() { ResponseId = context.Message.ResponseId, EventClusterIds = eventClusterIds }); if (result != null) { //Push message to Service bus queue for UI update _logger.LogDebug($"EventClusterAssignResponseRequestedConsumer: Event Cluster Ids added to response '{context.Message.ResponseId}'."); await context.Publish(new ResponseTaggedEventClusterEvents() { Response = result }); return; } _logger.LogError($"EventClusterAssignResponseRequestedConsumer: Event Cluster Ids could not be added to response '{context.Message.ResponseId}'."); throw new Exception($"Event Cluster Ids could not be added to response '{context.Message.ResponseId}'."); } _logger.LogError("EventClusterAssignResponseRequestedConsumer: Event Cluster Ids could not be retrieved."); throw new Exception("Event Cluster Ids could not be retrieved."); } catch (Exception e) { _logger.LogError($"EventClusterAssignResponseRequestedConsumer: {e.Message}"); throw e; } }
public async Task Consume(ConsumeContext <IResponseTagNewEventClusterRequested> context) { try { _logger.LogDebug($"ResponseTagNewEventClusterRequestedConsumer: Retrieved message from event cluster '{context.Message.EventClusterId}'."); //Check if responses are associated IEnumerable <ResponseModel> responsesAssociated = await _responseRestService.GetResponsesFromPointRadius(new ResponseGeolocationModel() { EventClusterGeolocationPointLocation = context.Message.EventClusterGeolocation }); if (responsesAssociated != null) { //Add to every matching response foreach (var responseAssociated in responsesAssociated) { //Add to matching response ResponseModel result = await _responseRestService.AddEventClusterIdsToResponse(new ResponseEventClustersUpdateModel() { ResponseId = responseAssociated.ResponseId, EventClusterIds = new List <Guid>() { context.Message.EventClusterId } }); if (result != null) { //Publish update for saga _logger.LogDebug($"ResponseTagNewEventClusterRequestedConsumer: Event Cluster Id added to response '{result.ResponseId}'."); await context.Publish(new ResponseTaggedEventClusterEvents() { Response = result }); return; } _logger.LogError($"ResponseTagNewEventClusterRequestedConsumer: Event Cluster Id could not be added to response '{result.ResponseId}'."); throw new Exception($"Event Cluster Id could not be added to response '{result.ResponseId}'."); } return; } } catch (Exception e) { _logger.LogError($"ResponseTagNewEventClusterRequestedConsumer: {e.Message}"); throw e; } }