예제 #1
0
        private static async void OnSubscriptionNotify(string server, ServiceEventMessage message)
        {
#if DEBUG
            Console.WriteLine("Consumed OnSubscriptionNotify message");
            Console.WriteLine("Server: " + server);
            Console.WriteLine("Message: " + message.ToString());
#endif
            string url      = (string)message.Parameters["Url"];
            string clientID = (string)message.Parameters["ClientID"];

            Model.WebhookNotification notification = new Model.WebhookNotification();
            MemoryStream stream = new MemoryStream(16384);
            new ServiceModels.WebhookNotification(notification, message).Serialise(stream);
            string payload = new StreamReader(stream).ReadToEnd();

            bool retry        = message.Parameters.ContainsKey("RequeueCount");
            long requeueCount = retry ? (long)message.Parameters["RequeueCount"] : 0;
            bool dropMessage  = false;

#if DEBUG
            Console.WriteLine($"Sending payload to {url}: \n" + payload);
#endif

            try
            {
                RESTClient.RESTResponse response = await RESTClient.PostAsync(url, ACCEPT_TYPE, null, notification.AcceptContentType, payload);

                switch ((HttpStatusCode)response.StatusCode)
                {
                case HttpStatusCode.OK:
                case HttpStatusCode.Created:
                    ApplicationEventLog.Write(LogLevel.Information, $"Webhook post notification from client {clientID} to {url} successful.");
                    break;

                case HttpStatusCode.BadRequest:
                case HttpStatusCode.Unauthorized:
                case HttpStatusCode.NotFound:
                case HttpStatusCode.MethodNotAllowed:
                    // No retry for these failures
                    ApplicationEventLog.Write(LogLevel.Warning, $"Non-recoverable HTTP Status code from{url}:{response.StatusCode}, discarding message.");
                    dropMessage = true;
                    break;

                default:
                    ApplicationEventLog.Write(LogLevel.Warning, $"Unexpected HTTP Status code from{url}:{response.StatusCode}");
                    break;
                }
            }
            catch (Exception ex)
            {
                ApplicationEventLog.Write(LogLevel.Error, "Failed to post webhook", ex);
            }

            if ((MAX_POST_ATTEMPTS <= 0 || requeueCount < MAX_POST_ATTEMPTS) && !dropMessage)
            {
                BusinessLogicFactory.ServiceMessages.NackMessage(message);
            }
        }
예제 #2
0
        private static async void OnSubscriptionNotify(string server, ServiceEventMessage message)
        {
#if DEBUG
            Console.WriteLine("Consumed OnSubscriptionNotify message");
            Console.WriteLine("Server: " + server);
            Console.WriteLine("Message: " + message.ToString());
#endif
            string url = (string)message.Parameters["Url"];
            string clientID = (string)message.Parameters["ClientID"];

            Model.WebhookNotification notification = new Model.WebhookNotification();
            MemoryStream stream = new MemoryStream(16384);
            new ServiceModels.WebhookNotification(notification, message).Serialise(stream);
            string payload = new StreamReader(stream).ReadToEnd();

            bool retry = message.Parameters.ContainsKey("RequeueCount");
            long requeueCount = retry ? (long)message.Parameters["RequeueCount"] : 0;
            bool dropMessage = false;

#if DEBUG
            Console.WriteLine($"Sending payload to {url}: \n" + payload);
#endif

            try
            {
                RESTClient.RESTResponse response = await RESTClient.PostAsync(url, ACCEPT_TYPE, null, notification.AcceptContentType, payload);

                switch ((HttpStatusCode)response.StatusCode)
                {
                    case HttpStatusCode.OK:
                    case HttpStatusCode.Created:
                        ApplicationEventLog.Write(LogLevel.Information, $"Webhook post notification from client {clientID} to {url} successful.");
                        break;
                    case HttpStatusCode.BadRequest:
                    case HttpStatusCode.Unauthorized:
                    case HttpStatusCode.NotFound:
                    case HttpStatusCode.MethodNotAllowed:
                        // No retry for these failures
                        ApplicationEventLog.Write(LogLevel.Warning, $"Non-recoverable HTTP Status code from{url}:{response.StatusCode}, discarding message.");
                        dropMessage = true;
                        break;
                    default:
                        ApplicationEventLog.Write(LogLevel.Warning, $"Unexpected HTTP Status code from{url}:{response.StatusCode}");
                        break;
                }
            }
            catch(Exception ex)
            {
                ApplicationEventLog.Write(LogLevel.Error, "Failed to post webhook", ex);
            }

            if ((MAX_POST_ATTEMPTS <= 0 || requeueCount < MAX_POST_ATTEMPTS) && !dropMessage)
            {
                BusinessLogicFactory.ServiceMessages.NackMessage(message);
            }
        }
예제 #3
0
        public WebhookNotification(Model.WebhookNotification webhookNotification, ServiceEventMessage message)
        {
            _WebhookNotification = webhookNotification;
            _WebhookNotification.AcceptContentType = (string)message.Parameters["AcceptContentType"];
            _WebhookNotification.SubscriptionID    = (string)message.Parameters["SubscriptionID"];
            _WebhookNotification.ClientID          = (string)message.Parameters["ClientID"];
            _WebhookNotification.SubscriptionType  = (string)message.Parameters["SubscriptionType"];
            _WebhookNotification.TimeTriggered     = (DateTime)message.Parameters["TimeTriggered"];
            if (message.Parameters.ContainsKey("Object"))
            {
                _WebhookNotification.ChangedObject = (Model.Object)message.Parameters["Object"];

                _WebhookNotification.ObjectDefinition = DataAccessFactory.ObjectDefinitions.GetLookups().GetObjectDefinition(_WebhookNotification.ChangedObject.ObjectDefinitionID);
                if (_WebhookNotification.ObjectDefinition == null)
                {
                    ApplicationEventLog.Write(LogLevel.Warning, $"Could not lookup object definition {_WebhookNotification.ChangedObject.ObjectDefinitionID}");
                }
            }
        }
        public WebhookNotification(Model.WebhookNotification webhookNotification, ServiceEventMessage message)
        {
            _WebhookNotification = webhookNotification;
            _WebhookNotification.AcceptContentType = (string)message.Parameters["AcceptContentType"];
            _WebhookNotification.SubscriptionID = (string)message.Parameters["SubscriptionID"];
            _WebhookNotification.ClientID = (string)message.Parameters["ClientID"];
            _WebhookNotification.SubscriptionType = (string)message.Parameters["SubscriptionType"];
            _WebhookNotification.TimeTriggered = (DateTime)message.Parameters["TimeTriggered"];
            if (message.Parameters.ContainsKey("Object"))
            {
                _WebhookNotification.ChangedObject = (Model.Object)message.Parameters["Object"];

                _WebhookNotification.ObjectDefinition = DataAccessFactory.ObjectDefinitions.GetLookups().GetObjectDefinition(_WebhookNotification.ChangedObject.ObjectDefinitionID);
                if (_WebhookNotification.ObjectDefinition == null)
                {
                    ApplicationEventLog.Write(LogLevel.Warning, $"Could not lookup object definition {_WebhookNotification.ChangedObject.ObjectDefinitionID}");
                }
            }
        }
예제 #5
0
 public WebhookNotification(Model.WebhookNotification webhookNotification)
 {
     _WebhookNotification = webhookNotification;
 }
 public WebhookNotification(Model.WebhookNotification webhookNotification)
 {
     _WebhookNotification = webhookNotification;
 }