Oracle:事件未传递到链事件步骤(DBMS_SCHEDULER.DEFINE_CHAIN_EVENT_STEP)

时间:2015-06-16 11:07:32

标签: oracle dbms-scheduler

我设置了一个调度程序链来测试链事件步骤对事件的反应 事件(消息)未送达。

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
"CORE   12.1.0.2.0  Production"
TNS for Linux: Version 12.1.0.2.0 - Production
NLSRTL Version 12.1.0.2.0 - Production

有什么想法吗?

谢谢, 沃尔夫冈

我为多个消费者定义了一个带有队列表wb_event_queue_tab的DBMS_AQADM队列wb_event_queue 以及队列表的以下类型。

CREATE OR REPLACE TYPE wb_event_msg_type AS OBJECT (  
  name    VARCHAR2(100),  
  result  NUMBER(5)  
);  

该链仅包含两个步骤。 第一个(使用DEFINE_CHAIN_STEP定义)将收件人列表中带有“SCHEDULER $ _EVENT_AGENT”的邮件排入队列

l_message_properties.recipient_list(0):=sys.aq$_agent(''SCHEDULER$_EVENT_AGENT'', null, null);

第一步(DEFINE_CHAIN_EVENT_STEP)在第一步完成后开始,以便从第一步开始接收事件。

DBMS_SCHEDULER.DEFINE_CHAIN_EVENT_STEP (
  chain_name => 'wb_chain_event_step'
  , step_name => 'wb_step_dequeue'
  , event_condition => 'tab.user_data.result=0'.
  , queue_spec => 'wb_event_queue'
);

我通过

运行链条
begin --run chain
  DBMS_SCHEDULER.RUN_CHAIN(
    chain_name => 'wb_chain_event_step'
    , job_name => 'wb_job_event_step'
    , start_steps => 'wb_step_enqueue'
  );
end;
/

但是,消息会在消息表中挂起 姓名为“SCHEDULER $ _EVENT_AGENT”的消费者会在事件队列中等待 作业wb_job_event_step没有完成。

设置代码。

CREATE OR REPLACE TYPE wb_event_msg_type AS OBJECT (  
  name    VARCHAR2(100),  
  result  NUMBER(5)  
);  
/  

begin --create queue
  DBMS_AQADM.create_queue_table (
    queue_table => 'wb_event_queue_tab'
    , queue_payload_type => 'wb_event_msg_type'
    , multiple_consumers => true
  );

  DBMS_AQADM.create_queue (
    queue_name => 'wb_event_queue'
    , queue_table => 'wb_event_queue_tab'
  );

  DBMS_AQADM.start_queue (
    queue_name => 'wb_event_queue'
    , enqueue => true
    , dequeue => true
  );
end;
/


declare --create chain
  my_job_action varchar2(4000) := ''
||'DECLARE'
||'  l_enqueue_options DBMS_AQ.enqueue_options_t;'
||'  l_message_properties DBMS_AQ.message_properties_t;'
||'  l_message_handle RAW(16);'
||'  l_event_msg wb_event_msg_type;'
||'BEGIN'
||'  l_message_properties.recipient_list(0) := sys.aq$_agent(''SCHEDULER$_EVENT_AGENT'', null, null);'
||'  l_event_msg := wb_event_msg_type(''wolfgang'', 0);'
||'  DBMS_AQ.enqueue(queue_name          => ''wb_event_queue'', '       
||'                  enqueue_options     => l_enqueue_options,     '
||'                  message_properties  => l_message_properties,   '
||'                  payload             => l_event_msg,             '
||'                  msgid               => l_message_handle);'
||''
||'END;'
;
BEGIN
  DBMS_SCHEDULER.CREATE_PROGRAM (
     program_name => 'wb_prog_result2event'
     , program_type => 'PLSQL_BLOCK'
     , program_action => my_job_action
     , number_of_arguments => 0
     , enabled => true
  );

  DBMS_SCHEDULER.CREATE_CHAIN(chain_name => 'wb_chain_event_step'); 

  DBMS_SCHEDULER.DEFINE_CHAIN_EVENT_STEP (
     chain_name => 'wb_chain_event_step'
     , step_name => 'wb_step_dequeue'
     , event_condition => 'tab.user_data.result=0'
     , queue_spec => 'wb_event_queue'
  );

  DBMS_SCHEDULER.DEFINE_CHAIN_STEP(
    chain_name => 'wb_chain_event_step'
    , step_name => 'wb_step_enqueue'
    , program_name => 'wb_prog_result2event'
  );

  DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
    chain_name  =>'wb_chain_event_step'
    , condition =>'true'
    , action    =>'start wb_step_enqueue'
    , rule_name =>'wb_rule_enqueue'
  ); 
  DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
    chain_name  =>'wb_chain_event_step'
    , condition =>'wb_step_enqueue COMPLETED'
    , action    =>'start wb_step_dequeue'
    , rule_name =>'wb_rule_dequeue'
  ); 
  DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
    chain_name  =>'wb_chain_event_step'
    , condition =>'wb_step_dequeue COMPLETED'
    , action    =>'end'
    , rule_name =>'wb_rule_end'
  ); 
  DBMS_SCHEDULER.ENABLE('wb_chain_event_step');

end;
/

清理代码。

execute dbms_scheduler.stop_job(job_name=>'wb_job_event_step');

begin --drop chain
  DBMS_SCHEDULER.DROP_CHAIN_RULE(
    chain_name => 'wb_chain_event_step'
    , rule_name=>'wb_rule_enqueue'
  );
  DBMS_SCHEDULER.DROP_CHAIN_RULE(
    chain_name => 'wb_chain_event_step'
    , rule_name=>'wb_rule_dequeue'
  );
  DBMS_SCHEDULER.DROP_CHAIN_RULE(
    chain_name => 'wb_chain_event_step'
    , rule_name => 'wb_rule_end'
  );
  DBMS_SCHEDULER.DROP_CHAIN_STEP(
    chain_name => 'wb_chain_event_step'
    , step_name => 'wb_step_enqueue'
  );
  DBMS_SCHEDULER.DROP_CHAIN_STEP(
    chain_name => 'wb_chain_event_step'
    , step_name => 'wb_step_dequeue'
  );
  DBMS_SCHEDULER.DROP_PROGRAM(
    program_name => 'wb_prog_result2event'
  );
  DBMS_SCHEDULER.DROP_CHAIN(
    chain_name => 'wb_chain_event_step'
  );
end;
/

begin --drop queue
  DBMS_AQADM.stop_queue (
    queue_name => 'wb_event_queue'
  );
  DBMS_AQADM.drop_queue(
    queue_name => 'wb_event_queue'
  );
  DBMS_AQADM.drop_queue_table(
    queue_table => 'wb_event_queue_tab'
end;
/

drop type wb_event_msg_type;
/  

0 个答案:

没有答案