Calling a REST API from a trigger or stored procedure in mysql?

僤鯓⒐⒋嵵緔 提交于 2021-02-09 10:46:16

问题


I want to call rest api in a POST method from a stored procedure or trigger in mysql server on windows.

How do I perform this solely with MySQL?


回答1:


You can use a mysql-udf-http and then create a trigger like this:

delimiter $$
CREATE TRIGGER upd_check BEFORE UPDATE ON account 
FOR EACH ROW 
  BEGIN 
    IF NEW.amount > 0 THEN 
      set @json = select json_object(account_id,amount) 
      select http_post('http://restservice.example.com/account/post',@json); 
    END IF; 
  END;$$ 

delimiter;



回答2:


Basically you can't. And if you could (thru the use of a UDF library) you shouldn't.

Mysql is a high performance db engine that you ought to respect for its core competencies. Other stakeholders and waiting for your query or transaction to wrap up, and they suffer while yours doesn't. It is not a webserver with callbacks from asynchronous calls. Triggers and stored procs need to get in and get out as they are often used in a Transactional setting.



来源:https://stackoverflow.com/questions/40470267/calling-a-rest-api-from-a-trigger-or-stored-procedure-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!