public async Task Post([FromBody] ConnectorNotificationModel notification)
        {
            // Handle Connector update events
            if (notification.NotificationType == NotificationType.ConnectorConfigCreated ||
                notification.NotificationType == NotificationType.ConnectorConfigUpdated ||
                notification.NotificationType == NotificationType.ConnectorConfigDeleted)
            {
                // Get a proxy to the partition of the Worker service that will process this connector.
                // This is a mechanism for scaling out the processing load for the connector. In this scheme, connectors
                // are scaled out across the cluster, as the connector ID is used as the partition key. Therefore, all
                // processing for a single connector will happen on one node. Other partitioning schemes may be used to
                // scale out in different ways to suit the connector type.
                var worker = ServiceProxy.Create <IReferenceConnectorWorkerService>(new Uri("fabric:/ReferenceConnectorSF/ReferenceConnectorWorkerService"),
                                                                                    new Microsoft.ServiceFabric.Services.Client.ServicePartitionKey(GetWorkerPartitionKey(notification.ConnectorId)));

                if (notification.NotificationType == NotificationType.ConnectorConfigCreated ||
                    notification.NotificationType == NotificationType.ConnectorConfigUpdated)
                {
                    await worker.UpsertConnectorConfig(notification.ConnectorConfig);
                }
                else
                {
                    await worker.DeleteConnectorConfig(notification.ConnectorId);
                }
            }
            // Handle ItemDestroyed events
            else if (notification.NotificationType == NotificationType.ItemDestroyed)
            {
                // TODO
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a ConnectorNotificationAcknowledgeModel to be used to acknowledge the results
 /// of processing of a connector notification.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="processingResult"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static ConnectorNotificationAcknowledgeModel ToAcknowledge(this ConnectorNotificationModel model,
                                                                   ProcessingResult processingResult,
                                                                   string message = "")
 {
     return(new ConnectorNotificationAcknowledgeModel
     {
         ConnectorId = model.ConnectorId,
         NotificationId = model.Id,
         ProcessingResult = processingResult.ToString(),
         ConnectorStatusMessage = message
     });
 }
 private async Task AcknowledgeNotification(ConnectorNotificationModel model, ProcessingResult processingResult, string message)
 {
     try
     {
         await NotificationPullManager.AcknowledgeNotification(
             ApiClientFactorySettings,
             AuthenticationHelperSettingsFactory(_connectorConfig),
             model.ToAcknowledge(processingResult, message)).ConfigureAwait(false);
     }
     catch (ResourceNotFoundException)
     {
         // The notification couldn't be acked because it wasn't found.
         // This may happen if the notification was already acked - in this case,
         // the next iteration of the poller won't receive this notification again.
         Log?.LogWarning(GetType(), nameof(AcknowledgeNotification), $"{_logPrefix} - Notification with ID [{model.Id}] was not acknowledged because it could not be found " +
                         "in the Records365 notification queue. It may have already been acknowledged.");
     }
 }
        private async Task ProcessNotification(ConnectorNotificationModel notification)
        {
            string           processingErrorMessage = string.Empty;
            ProcessingResult processingResult       = ProcessingResult.OK;

            try
            {
                await NotificationHandler.HandleNotification(_connectorConfig, notification, _cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex) when(!ex.IsTaskCancellation(_cancellationToken))
            {
                Log?.LogWarning(GetType(), nameof(ProcessNotification), $"{_logPrefix} - Unhandled exception encountered - [{ex}]");
                processingResult       = ProcessingResult.NotificationError;
                processingErrorMessage = ex.Message;
            }

            await AcknowledgeNotification(notification, processingResult, processingErrorMessage).ConfigureAwait(false);
        }
 public void AddNotification(ConnectorNotificationModel model)
 {
     Dictionary.AddOrUpdate(model.Id, model, (k, v) => model);
 }