2014-06-27 Created By BaoXinjian
一、摘要
在之前的博文中介绍了,如何获取从标砖business event抓取消息,如supplier event,
其实质,就是在supplier的任何create, update, delete的处理,都是通过interface和api进行处理的, 而在处理interface和api的package中都会通过wf_event.raise将消息进行传递出来
再通过其他的package对在队列中的消息进行处理,从而实现消息的异步处理,实现interface的处理的主功能和辅助部分进行异步分离
本文介绍了如何运用完全客制化的business event进行客制化消息的传递
在百度文库中,黄建华大神也有非常详细的介绍
二、案例
案例: 建立一个完全客制化的business event,对该event消息触发和传递进行控制
Step1. 建立客制化表,存放从wf_event.raise传递出来的消息
1 --Create table
2 create table BXJ_BES_EVENT_DEMO
3 (
4 DEMO_ID NUMBER,
5 MESSAGE_NAME VARCHAR2(100),
6 MESSAGE_KEY VARCHAR2(100),
7 MESSAGE_CONTENTS CLOB,
8 PARAMETER_VALUE1 VARCHAR2(4000),
9 PARAMETER_VALUE2 VARCHAR2(4000),
10 EVENT_DATE DATE
11 );
12
13 --Create Sequence
14 CREATE SEQUENCE BXJ_BES_DEMO_S;
Step2. 建立package用以抓取event
1 --Create Package Header
2 CREATE OR REPLACE PACKAGE apps.bxj_bes_event_demo_pkg AUTHID CURRENT_USER AS
3 FUNCTION process_an_event(p_sub_guid IN RAW,
4 p_event IN OUT NOCOPY wf_event_t)
5 RETURN VARCHAR2;
6 END;
7
8 --Create Package Body
9 CREATE OR REPLACE PACKAGE BODY apps.bxj_bes_event_demo_pkg AS
10 FUNCTION process_an_event(p_sub_guid IN RAW,
11 p_event IN OUT NOCOPY wf_event_t)
12 RETURN VARCHAR2 IS
13 l_demo_rec bxj_bes_event_demo%ROWTYPE;
14 BEGIN
15 SELECT bxj_bes_demo_s.NEXTVAL INTO l_demo_rec.demo_id FROM dual;
16 --get evevent itself
17 l_demo_rec.message_name := p_event.geteventname;
18 l_demo_rec.event_date := p_event.getsenddate;
19 --we can use this key to transfer message only
20 l_demo_rec.message_key := p_event.geteventkey;
21 --optional, get xml data
22 l_demo_rec.message_contents := p_event.geteventdata;
23 --optional, get parameter
24 l_demo_rec.parameter_value1 := p_event.getvalueforparameter('Parameter1');
25 l_demo_rec.parameter_value2 := p_event.getvalueforparameter('Parameter2');
26 --do anything here
27 INSERT INTO bxj_bes_event_demo VALUES l_demo_rec;
28 RETURN 'SUCCESS';
29 EXCEPTION
30 WHEN OTHERS THEN
31 RETURN 'ERROR';
32 END;
33 END;
Step3. 建立Event
Step4.1 建立Subscription
Step4.2 建立subscription中的header信息
Step4.3 建立subscription中的detail信息
三、测试方式1 - 通过页面功能调用event
Test1. 调用event 测试功能
Test2. 输入event key和参数后,raise 该消息
Test3. 确认结果,消息是否传递成功
四、案例测试方式2 - 通过调用脚本触发event
Test1. 调用脚本wf_event触发event
DECLARE
x_parameters wf_parameter_list_t;
l_event_data CLOB;
BEGIN
wf_event.addparametertolist(p_name => 'Parameter1',
p_value => 'gavin',
p_parameterlist => x_parameters);
wf_event.addparametertolist(p_name => 'Parameter2',
p_value => 'bao',
p_parameterlist => x_parameters);
l_event_data := '<?xml version="1.0" encoding="UTF-8"?><root><Name>xinjian.bao</Name></root>';
wf_event.RAISE(p_event_name => 'bxj.business.events.demo',
p_event_key => 'event_key_005',
p_event_data => l_event_data,
p_parameters => x_parameters,
p_send_date => SYSDATE);
END;
Test2. 在结果表中,确认消息是否传递冲给你
Thanks and Regards
ERP技术讨论群: 288307890
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建