oracle10g simpe AQ step by step(一)
建立使用者、分配許可權
select * from dba_users t ;
---create on db1 SYS
create user oe identified by oe;
grant dba to oe;
create tablespace aq
datafile 'd:\oracle\aq.dbf' size 500m
extent management local
segment space management auto;
grant execute on dbms_aq to oe;
create user strmadmin identified by strmadmin
default tablespace aq
temporary tablespace temp;
grant dba to strmadmin;
grant execute on dbms_streams_adm to strmadmin;
grant execute on dbms_transform. to strmadmin;
----session db1 strmadmin
設定安全佇列,建立對列
begin
dbms_streams_adm.set_up_queue(queue_table => 'oe_qtab_any',queue_name => 'oe_queue_any',queue_user => 'oe');
end;
/
設定佇列的代理,並且為代理設定安全命名
declare
subscriber sys.aq$_agent;
begin
subscriber := sys.aq$_agent('LOCAL_AGENT',NULL,NULL);
sys.dbms_aqadm.add_subscriber(queue_name => 'strmadmin.oe_queue_any',subscriber => subscriber);
end;
/
begin
dbms_aqadm.enable_db_access(agent_name => 'local_agent',db_username => 'oe');
end;
/
-----session DB1 oe
建立一個佇列物件型別
create or replace type cust_address_type as object (
address varchar2(40),
nos varchar2(10),
firstname varchar2(10),
middname varchar2(10),
lastname varchar2(10)
);
/
--------------SESSION DB1 OE
建立入隊儲存過程
create or replace procedure oe.enq_proc(payload anydata)
is
enqopt dbms_aq.enqueue_options_t;
mprop dbms_aq.message_properties_t;
enq_msgid raw(16);
begin
mprop.sender_id := sys.aq$_agent('LOCAL_AGENT',NULL,NULL);
dbms_aq.enqueue(queue_name => 'strmadmin.oe_queue_any',enqueue_options => enqopt,message_properties => mprop,payload => payload,msgid => enq_msgid);
end;
/
入隊一個字元創
begin
oe.enq_proc(anydata.ConvertVarchar2('Chemicals - SW'));
COMMIT;
end;
入隊一個數字
begin
oe.enq_proc(anydata.ConvertNumber('16'));
commit;
end;
/
入隊一個使用者自定義物件
begin
oe.enq_proc(anydata.ConvertObject(oe.cust_address_type('1666 aaaaa','3333333','qin','qiang','ai')));
commit;
end;
/
檢視佇列表
-----session strmadmin
select * from strmadmin.aq$oe_qtab_any;
-----session oe
建立出列儲存過程
create or replace procedure oe.get_cust_address(consumer in varchar2) as
address oe.cust_address_type;
deq_address anydata;
msgid raw(16);
deqopt dbms_aq.dequeue_options_t;
mprop dbms_aq.message_properties_t;
new_address boolean := true;
next_trans exception;
no_message exception;
pragma exception_init (next_trans,-25235);
pragma exception_init (no_message,-25228);
num_var pls_integer;
begin
deqopt.consumer_name := consumer;
deqopt.wait :=1;
while (new_address) loop
begin
dbms_aq.dequeue(queue_name => 'strmadmin.oe_queue_any',dequeue_options => deqopt,message_properties => mprop,payload => deq_address,msgid => msgid);
deqopt.navigation := dbms_aq.next;
dbms_output.put_line('********************');
if(deq_address.getTypeName() = 'OE.CUST_ADDRESS_TYPE') then
dbms_output.put_line('Message type is:'||deq_address.getTypeName());
num_var := deq_address.getObject(address);
dbms_output.put_line('*****customer address *****');
dbms_output.put_line(address.address);
dbms_output.put_line(address.nos);
dbms_output.put_line(address.firstname);
dbms_output.put_line(address.middname);
dbms_output.put_line(address.lastname);
else
dbms_output.put_line('Message type is:'||deq_address.getTypeName());
end if;
commit;
exception
when next_trans then
deqopt.navigation := dbms_aq.next_transaction;
when no_message then
new_address := false;
dbms_output.put_line('no more messages');
end;
end loop;
end;
/
出列
begin
oe.get_cust_address('LOCAL_AGENT');
end;
簡單的一個AQ demo,後面還有remot、LCRS、JMS慢慢增加。。哈哈。。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10130206/viewspace-625507/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle10g simpe AQ step by step(二)Oracle
- Step By Step Install Oracle10g RAC On Hp-uxOracleUX
- React Step by StepReact
- Command 模式 Step by Step模式
- BAPI Step by step GuidanceAPIGUI
- Step by Step TimesTen --- ttIsqlSQL
- Step By Step Instructions on Migrating Oracle10g Database to Automatic Storage management (ASM)StructOracleDatabaseASM
- Promise的實現(step by step)Promise
- Learn c++ step by step (轉)C++
- 使用RMAN備份集搭建Oracle Dataguard Step by Step(一)Oracle
- Oracle 11gR2 Active DataGuard配置Step By Step(一)Oracle
- Step by Step TimesTen --- DataStore的雙向複製( 一)AST
- GoldenGate<一> step by step installation and configurationGo
- Linux Software RAID step by stepLinuxAI
- Git Step by Step (3):Git物件模型Git物件模型
- Oracle高階複製Step by StepOracle
- 安裝linux(step by step)(轉)Linux
- Learn C++ step by step(2) (轉)C++
- 單步除錯 step into/step out/step over 區別詳解除錯
- 轉載一個step by step change public-ip and vip on RAC
- ABP應用開發(Step by Step)-下篇
- ABP應用開發(Step by Step)-上篇
- TIDB DM資料同步step by stepTiDB
- Git Step by Step (4):探索.git目錄Git
- ClearCase使用入門--step by step(序) (轉)
- Oracle 12c GI/RAC Step-by-Step安裝指南(一)Oracle
- Step by Step, 為OSRFX2建立一個KMDF驅動程式
- 實時 Linux 抖動分析 Step by stepLinux
- Git Step by Step (6):Git遠端倉庫Git
- STEP BY STEP INSTALL SSH ON AIX5.3(6.1)AI
- install 11G ASM on RedHat step by stepASMRedhat
- linux中配置NFS服務step by stepLinuxNFS
- step by step install netbackup client 6.5 on aixclientAI
- Step by Step Data Replication Using Oracle GoldenGateOracleGo
- Oracle 10g R2建立ASM例項Step By Step(一)Oracle 10gASM
- STREAMS筆記(1) step by step 建立一個Streams複製環境筆記
- Step by Step 安裝 BizTalk Server 2009Server
- Baby-Step-Gaint-Step演算法詳解AI演算法