【发布时间】:2017-08-09 22:59:13
【问题描述】:
我们如何invoke c# windows service(或)dll 来自 Oracle AFTER INSERT Trigger 的文件
任何建议都将受到高度赞赏
最好的问候,
【问题讨论】:
-
你试过什么?请提出具体问题并提供代码示例。这是一个类似的问题:stackoverflow.com/questions/14918695/…
我们如何invoke c# windows service(或)dll 来自 Oracle AFTER INSERT Trigger 的文件
任何建议都将受到高度赞赏
最好的问候,
【问题讨论】:
作为一项规则,Windows 服务并非旨在根据特定请求调用,它应该在后台连续运行。
为了让 Oracle DB 执行某些操作,您首先需要在表上使用一个触发器来监控插入。
那么,这应该调用一个java存储过程。然后,此存储过程可以在消息总线上发送消息,您的服务可以接收并处理该消息。
见:
Sending a JMS Message from Oracle Database on DML Event
Oracle: Java stored procedure sending JMS Message
https://docs.oracle.com/cd/B19306_01/server.102/b14257/jm_point.htm
另一种方法是让java存储过程调用外部程序
【讨论】:
我通过使用utl_http 使Oracle 触发器调用WebApi 服务解决了这个问题。这样,“服务”可以等待请求并且触发器是轻触的。这是我的触发器示例:
declare
content varchar2(4000);
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://server.com/api/Function';
begin
content := '{ "Message": "Hello" }';
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'application/json');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req);
if res.status_code <> 200 then
dbms_output.put_line(res.reason_phrase);
end if;
utl_http.end_response(res);
end;
您可以将任何您想要的逻辑放入 WebApi 端点。如果你真的想要一个 Windows 服务,你可以让触发器写入 RabbitMQ 之类的东西,并让服务消耗交换队列。
【讨论】:
url varchar2(4000) := 'http://server.com/api/Function';