コード例 #1
0
 public ResponseDetailsBase PushMessageToQueue(VehicleDto vehicle)
 {
     using (var channel = _messaginQueueHandler.CreateConnection())
     {
         _logger.LogInformation("Push Message To Service Bus is starting");
         if (vehicle == null || string.IsNullOrEmpty(vehicle.VehicleId))
         {
             _logger.LogInformation("Cannot Retrieve Random Vehicle");
             return(new ResponseDetailsBase(ResponseStatusCode.InvalidInputs));
         }
         var pingComm = new PingVehicleModel()
         {
             Id        = Guid.NewGuid(),
             CreatedAt = DateTime.UtcNow,
             VehicleId = vehicle.VehicleId
         };
         var pushMessageResponse = _messaginQueueHandler.PushMessage(pingComm, channel);
         if (pushMessageResponse.StatusCode != ResponseStatusCode.Success)
         {
             _logger.LogInformation("Failed To Update Vehicle Status");
         }
         _logger.LogInformation("Vehicle Status Updated Successfully");
         return(pushMessageResponse);
     }
 }
コード例 #2
0
 public bool PullMessageFromServiceBus(object state)
 {
     using (var channel = _messaginQueueHandler.CreateConnection())
     {
         var pullResponse = _messaginQueueHandler.PullMessage <PingVehicleModel>(channel);
         if (pullResponse == null || pullResponse.StatusCode != ResponseStatusCode.Success)
         {
             return(false);
         }
         var pingVehicleResponse = _customerService.UpdateVehicleStatus(pullResponse.DetailsObject);
         if (pingVehicleResponse.StatusCode != ResponseStatusCode.Success)
         {
             _logger.LogInformation("Failed To Update Vehicle");
             return(false);
         }
         _messaginQueueHandler.AckNowledge(pullResponse.SecondDetailsObject, channel);
         _logger.LogInformation("Pull Message From Service Bus Is Completed");
         return(true);
     }
 }