Page 1 of 1

Webhook Double up

PostPosted: Fri Jan 29, 2021 10:49 am
by SBarnes
I am getting an issue with a debtor.updated webhook that whilst working and posting instantly is being sent twice, is there any reason this would be happening, this is with Jiwa 7.2.0 SR6?

Re: Webhook Double up

PostPosted: Fri Jan 29, 2021 3:09 pm
by Mike.Sheen
SBarnes wrote:I am getting an issue with a debtor.updated webhook that whilst working and posting instantly is being sent twice, is there any reason this would be happening, this is with Jiwa 7.2.0 SR6?


I have had this reported before - there is some sort of issue with the aync nature of sending webhooks and the retry mechanism that we need to review.

I think it's related to the retry timer picking up a message as unsent inbetween the time the message is added to the queue and the initial sending (POST). Increasing the WebhooksRetryInterval system setting may help.

Re: Webhook Double up

PostPosted: Fri Jan 29, 2021 3:14 pm
by Mike.Sheen
What does the WebhookMessagesTimer constructor look like in your REST API plugin?

I can see in 7.2.1 it's no longer asynchronously sending unsent or failed messages.

Re: Webhook Double up

PostPosted: Fri Jan 29, 2021 3:22 pm
by SBarnes
Ok thanks I'll try that by changing the setting on a related issue I am trying to do a webhook double hop for an inventory update which has service function like


Code: Select all
public ServiceStack.Web.IHttpResult Post(JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem request)


but request is the correct InventoryIem but all the properties aren't being set however, in other words it not deserializing the body

Code: Select all
string reqbody = base.Request.GetRawBody();


will actually get me the data that I need to do the hop but it seems a bit cludgy, I tried looking at IRequiresRequestStream but that didn't work any ideas on how to make it deserialize the body, in web api there is an annotation to do it?

The webhook message timer constructor is

Code: Select all
 public WebhookMessagesTimer(int TimerInterval)
        {
            _timer = new System.Timers.Timer { AutoReset = false, Interval = TimerInterval };

            _timer.Elapsed += delegate
            {
                _timer.Stop();

                //                  List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();                  

                // Process the message queue
                List<SY_WebhookMessage> messages = RESTAPIPlugin.WebhookMessages.OrderBy(x => x.ItemNo).ToList<SY_WebhookMessage>();
                foreach (SY_WebhookMessage message in messages)
                {
                    //                     System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(() => { WebHookController.CallWebhook(message); } );
                    //                          tasks.Add(task);
                    WebHookController.CallWebhook(message);
                }

                //                  if (tasks.Count > 0)
                //                  {                        
                //                     System.Threading.Tasks.Task.WaitAll(tasks.ToArray());
                //                     tasks.Clear();
                //                  }

                _timer.Start(); // restart the timer
            };

            _timer.Start();
        }

Re: Webhook Double up

PostPosted: Fri Jan 29, 2021 3:40 pm
by SBarnes
Hi Mike

Increasing the retry interval fixes the double up issue.

Re: Webhook Double up

PostPosted: Mon Feb 15, 2021 10:44 am
by SBarnes
Hi Mike,

Whilst we have resolved the double up on our development server, under Azure our client is claiming that a hook is being received 4 times at the other end, I have checked the message and response tables and don't believe that this is at the Jiwa api end given the query results.

To troubleshoot this I have done the following:

1. After backing up the message and response tables I have flushed them of data.
2. I have increased the retry interval to 20 seconds so there is no danger of overlaps in the retries
3. I have lowered the retries to 2 in the theory if they keep keep getting 4 messages the problem won't be at the Jiwa end and this will prove it.

Do you have any other trouble shooting ideas besides the above?

Re: Webhook Double up

PostPosted: Mon Feb 15, 2021 5:00 pm
by SBarnes
Ok this is weird the following SQL is returning data, should it?

Code: Select all
SELECT        dbo.SY_WebhookSubscription.RecID, dbo.SY_WebhookSubscription.SY_WebhookSubscriber_RecID, dbo.SY_WebhookSubscription.EventName, dbo.SY_WebhookSubscription.URL,
                         dbo.SY_WebhookSubscriber.Name, dbo.SY_WebhookSubscriber.RecID AS SY_WebhookSubscriberRecID
FROM            dbo.SY_WebhookSubscription LEFT OUTER JOIN
                         dbo.SY_WebhookSubscriber ON dbo.SY_WebhookSubscription.SY_WebhookSubscriber_RecID = dbo.SY_WebhookSubscriber.RecID
WHERE        (dbo.SY_WebhookSubscriber.RecID IS NULL)