I have to call a REST endpoint from OpenEdge DB trigger.
Looking for some code snippet or pointers.
You most probably don't have nor should do this from a trigger, other than that REST means simply a HTTP request and depending on your OS/Progress versions you can go with an os-command to curl, make a socket connection over or use the new .Net package in 11.5+.
The idea is to know real time when changes have happened on database.
Would using curl be scalable?
As others have said.... Don't put the logic inside of the trigger. Rollbacks will be an issue because the rest call will not be rolled back with the data. You also have the real chance of transactions lasting much longer in the case of network errors or downstream issues.
Add a datetime column and populate it during the trigger. Or create queue records in the triggers. Then have one or more jobs that process the changed records and call the rest service.
Real time is essentially a myth for database applications. Near real time is as good as it gets for any non trivial application.
"create queue records"? you mean create records in a special table, to work like a queue of DB events?
And consume those records to call REST?
- Would this idea scale for high volumes on transaction tables?
- Second, can one of you provide me a snippet of code to make the REST call from the background process. I have my Progress DB deployed on Linux. so need a solution that does not need Windows.
>> - Would this idea scale for high volumes on transaction tables?
Yes it would.
>> - Second, can one of you provide me a snippet of code to make the REST call from the background process. I have my Progress DB deployed on Linux. so need a solution that does not need Windows.
On Linux your best bets would be to shell out and use CURL or (perhaps) use our HTTP classes, however, I haven't done much with them and am not certain that they work on non-Windows platforms. Someone else would have to jump in on that point.
As far as code snippets, unfortunately I don't have any. If you are not interested in trying to write the code yourself I would suggest that you use google, find some sample code (even if in a different language) then try converting that.
It will scale as well as you design it for multi threading and as your hardware allows. Make the wrong design choices and it will suffer.
cURL would be the easiest path since it handles pretty much everything by setting various options.
I would suggest doing quite a bit of testing before you deploy this in a production environment.
cURL is pretty simple to use. But if you wish to use the ABL .NET Classes for invoking REST Services, then let me know. I can provide you some samples
Irfan, Thanks for the suggestion. So invoke cURL from Progress code?
I am interested in either or both samples you have to offer.
cURL is a command line utility. You can run it from ABL from OS-COMMAND or which ever way you prefer.
But if you are using ABL ,then you can consider using ABL HTTP Client(If your OE version is 11.5)
I have attached the documentation for ABL HTTP Classes in this post