SBarnes wrote:We have a client with webhooks set up for a debtor update the business logic is firing and creating an entry in SY_WebhookMessage but the response only shows up in SY_WebhookMessageResponse and in the receiver of the webhook when the service is restarted, how can we diagnose what is going wrong?
static async public System.Threading.Tasks.Task Webhook(JiwaFinancials.Jiwa.JiwaApplication.Manager Manager, string body, string eventName)
{
string url = Manager.Database.ReadSysData("REST API", "WebhooksHostURL", "").ToString();
string clientKey = Manager.Database.ReadSysData("REST API", "WebhooksClientKey", "").ToString();
if (url.Length > 0)
{
try
{
ServiceStack.JsonServiceClient client = new ServiceStack.JsonServiceClient(url);
client.Headers.Add("ClientKey", clientKey);
await client.PostAsync<IReturnVoid>(new JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest() { EventName = eventName, Body = body });
}
catch (System.Exception ex)
{
// Don't throw if the above fails - we don't want to stop the user continuing on if there was a problem with the REST API, but we do want to try to insert into the message queue table so when the service comes up it knows about these items it missed
string sql = @"INSERT INTO SY_WebhookMessage(RecID, SY_WebhookSubscription_RecID, Body, ItemNo, Status, LastSavedDateTime, AddedDateTime, Retries)
SELECT NewID(), SY_WebhookSubscription.RecID, @Body,
COALESCE(QueueTable.MaximumItemNo, 0) + ROW_NUMBER() OVER (ORDER BY (SELECT NULL)),
0, SYSUTCDATETIME(), SYSUTCDATETIME(), 0
FROM SY_WebhookSubscription
CROSS JOIN (SELECT MAX(ItemNo) AS MaximumItemNo FROM SY_WebhookMessage) QueueTable
WHERE EventName = @EventName
ORDER BY SY_WebhookSubscription.ItemNo";
var dbFactory = new OrmLiteConnectionFactory(Manager.Database.ConnectionString, ServiceStack.OrmLite.SqlServer2012Dialect.Provider);
using (var db = dbFactory.Open())
{
db.ExecuteSql(sql, new {Body = body, EventName = eventName} );
}
}
}
}
Users browsing this forum: No registered users and 1 guest