oracle 高级队列
转载:http://www.idevelopment.info/data/Oracle/DBA_tips/Advanced_Queuing/AQ_2.shtml
Overview
This article provides a brief overview on configuring and using Oracle's Advanced Queuing features using PL/SQL. This will demonstrate the basic functionality of Oracle Advanced Queuing (AQ). AQ was first introduced in Oracle8 and has been extended and improved on into future versions.
Setup and Configuration
Within this section of the article, I provide the steps required to configure our QA environment. This involves creating users and assigning them the privileges required to perform all necessary AQ operations.
Before creating the users, let's take a look at the two major roles that are provided for performing AQ administration and user operations:
AQ_ADMINISTRATOR_ROLE
This role allows for the creation and administration of the queuing infrastructure.
AQ_USER_ROLE
This role allows users to access queues for enqueue and dequeue operations.
Now, let's create the following two schemas; one owning the queuing infrastructure and another with access to it:
create_aq_users.sql
CONNECT sys/change_on_install as sysdba -- ------------------------------------------------------- DROP USER aq_admin_plsql CASCADE; CREATE USER aq_admin_plsql IDENTIFIED BY aq_admin_plsql
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp; ALTER USER aq_admin_plsql QUOTA UNLIMITED ON users; GRANT aq_administrator_role TO aq_admin_plsql;
GRANT connect TO aq_admin_plsql;
GRANT create type TO aq_admin_plsql;
GRANT create sequence TO aq_admin_plsql; EXECUTE dbms_aqadm.grant_type_access('aq_admin_plsql'); -- ------------------------------------------------------- DROP USER aq_user_plsql CASCADE; CREATE USER aq_user_plsql IDENTIFIED BY aq_user_plsql
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp; GRANT aq_user_role TO aq_user_plsql;
GRANT connect TO aq_user_plsql;
Define Payload
The content, or payload, of a message is often defined using an OBJECT TYPE. We must define this before creating the queue. We also grant EXECUTE on the payload object type to our AQ user:
create_payload.sql
CONNECT aq_admin_plsql/aq_admin_plsql CREATE TYPE message_type AS OBJECT (
message_id NUMBER(15)
, subject VARCHAR2(100)
, text VARCHAR2(100)
, dollar_value NUMBER(4,2)
)
/ GRANT EXECUTE ON message_type TO aq_user_plsql; CREATE SEQUENCE message_seq
INCREMENT BY 1
START WITH 1000
NOMAXVALUE
NOCYCLE; GRANT select ON message_seq TO aq_user_plsql;
Create Queue Table and Queue
Now that we have the payload created, it is time to create the queuing infrastructure. Queues are implemented using a queue table which can hold multiple queues with the same payload type.
First the queue table must be defined using the payload type, then the queue can be defined and started. All of these operations can be performed using the DBMS_AQADM package as follows:
create_queue_table_and_queue.sql
CONNECT aq_admin_plsql/aq_admin_plsql SET SERVEROUTPUT ON BEGIN -- ------------------------------------------------------- DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'aq_admin_plsql.msg_qt'
, queue_payload_type => 'aq_admin_plsql.message_type'
); -- ------------------------------------------------------- DBMS_AQADM.CREATE_QUEUE (
queue_name => 'msg_queue'
, queue_table => 'aq_admin_plsql.msg_qt'
, queue_type => DBMS_AQADM.NORMAL_QUEUE
, max_retries => 0
, retry_delay => 0
, retention_time => 1209600
, dependency_tracking => FALSE
, comment => 'Test Object Type Queue'
, auto_commit => FALSE
); -- ------------------------------------------------------- DBMS_AQADM.START_QUEUE('msg_queue'); -- ------------------------------------------------------- DBMS_AQADM.GRANT_QUEUE_PRIVILEGE (
privilege => 'ALL'
, queue_name => 'aq_admin_plsql.msg_queue'
, grantee => 'aq_user_plsql'
, grant_option => FALSE
); -- ------------------------------------------------------- END;
/
Enqueue Message
Use the DBMS_AQ.ENQUEUE procedure to write messages to the queue:
enqueue_message.sql
CONNECT aq_user_plsql/aq_user_plsql SET SERVEROUTPUT ON DECLARE enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq_admin_plsql.message_type;
message_id NUMBER; BEGIN -- ------------------------------------------------------- SELECT aq_admin_plsql.message_seq.nextval
INTO message_id
FROM dual; -- ------------------------------------------------------- message := AQ_ADMIN_PLSQL.MESSAGE_TYPE (
message_id
, 'Subject: EXAMPLE MESSAGE'
, 'Message: THIS IS A SAMPLE MESSAGE.'
, 10.2
); -- ------------------------------------------------------- enqueue_options.VISIBILITY := DBMS_AQ.ON_COMMIT;
enqueue_options.SEQUENCE_DEVIATION := null; -- ------------------------------------------------------- message_properties.PRIORITY := -5;
message_properties.DELAY := DBMS_AQ.NO_DELAY;
message_properties.EXPIRATION := DBMS_AQ.NEVER;
message_properties.CORRELATION := 'TEST MESSAGE'; -- ------------------------------------------------------- DBMS_AQ.ENQUEUE (
queue_name => 'aq_admin_plsql.msg_queue'
, enqueue_options => enqueue_options
, message_properties => message_properties
, payload => message
, msgid => message_handle
); -- ------------------------------------------------------- COMMIT; -- ------------------------------------------------------- END;
/
Dequeue Message
Use the DBMS_AQ.DEQUEUE procedure to read messages from the queue:
dequeue_message.sql
CONNECT aq_user_plsql/aq_user_plsql SET SERVEROUTPUT ON DECLARE dequeue_options dbms_aq.dequeue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq_admin_plsql.message_type; BEGIN -- ------------------------------------------------------- dequeue_options.CONSUMER_NAME := NULL;
dequeue_options.DEQUEUE_MODE := DBMS_AQ.REMOVE;
dequeue_options.NAVIGATION := DBMS_AQ.NEXT_MESSAGE;
dequeue_options.VISIBILITY := DBMS_AQ.IMMEDIATE;
dequeue_options.WAIT := DBMS_AQ.FOREVER;
dequeue_options.MSGID := null;
dequeue_options.CORRELATION := 'TEST MESSAGE'; -- ------------------------------------------------------- DBMS_AQ.DEQUEUE (
queue_name => 'aq_admin_plsql.msg_queue'
, dequeue_options => dequeue_options
, message_properties => message_properties
, payload => message
, msgid => message_handle
); -- ------------------------------------------------------- dbms_output.put_line('+-----------------+');
dbms_output.put_line('| MESSAGE PAYLOAD |');
dbms_output.put_line('+-----------------+');
dbms_output.put_line('- Message ID := ' || message.message_id);
dbms_output.put_line('- Subject := ' || message.subject);
dbms_output.put_line('- Message := ' || message.text);
dbms_output.put_line('- Dollar Value := ' || message.dollar_value); -- ------------------------------------------------------- COMMIT; -- ------------------------------------------------------- END;
/Script Output Connected.
+-----------------+
| MESSAGE PAYLOAD |
+-----------------+
- Message ID := 1000
- Subject := Subject: EXAMPLE MESSAGE
- Message := Message: THIS IS A SAMPLE MESSAGE.
- Dollar Value := 10.2 PL/SQL procedure successfully completed.
Dropping All Objects
drop_aq_objects.sql
connect aq_admin_plsql/aq_admin_plsql EXECUTE dbms_aqadm.stop_queue(queue_name => 'aq_admin_plsql.msg_queue');
EXECUTE dbms_aqadm.drop_queue(queue_name => 'aq_admin_plsql.msg_queue');
EXECUTE dbms_aqadm.drop_queue_table(queue_table => 'aq_admin_plsql.msg_qt'); DROP TYPE aq_admin_plsql.message_type; DROP SEQUENCE aq_admin_plsql.message_seq; connect sys/change_on_install as sysdba DROP USER aq_user_plsql CASCADE;
DROP USER aq_admin_plsql CASCADE;
oracle 高级队列的更多相关文章
- oracle 高级分组
oracle 高级分组 博客分类: 数据库基础 oraclesql 10.高级分组 本章目标: 对于增强的group by需要掌握: 1.使用rollup(也就是roll up累计的意思)操作产生s ...
- oracle检查点队列与增量检查点【转载】
oracle检查点队列与增量检查点 今天是2013-09-04,这几天一直心里安顿不下来,今天还好了,可以自己安静的学习一下oracle,在此记录一下学习笔记.这篇文章我不知道在那转载的,一直都留在我 ...
- oracle高级查询(实例基于scott用户四张表)
oracle高级查询(实例基于scott用户四张表) 分组查询 多表查询 子查询 综合实例 ====================================================== ...
- oracle 高级函数2
原 oracle 高级函数 2017年08月17日 16:44:19 阅读数:1731 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u013278 ...
- oracle 高级函数
原 oracle 高级函数 2017年08月17日 16:44:19 阅读数:1731 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u013278 ...
- Oracle高级查询之OVER
注释:为了方便大家学习和测试,所有的例子都是在Oracle自带用户Scott下建立的 oracel的高级用法:rank()/dense_rank() over(partition by ...orde ...
- [转]详解Oracle高级分组函数(ROLLUP, CUBE, GROUPING SETS)
原文地址:http://blog.csdn.net/u014558001/article/details/42387929 本文主要讲解 ROLLUP, CUBE, GROUPING SETS的主要用 ...
- Oracle高级函数
http://www.cnblogs.com/chen1388/archive/2010/07/06/1771919.html decode函数: decode(aa, 1, 'xs', 2, 'ps ...
- oracle检查点队列(checkpoint queue)
buffer cache CBC链 按地址链 LRU 干净buffer LRUW 脏buffer 按照冷热 checkpoint queue:链buffer,①链脏块②按buffer第一次脏的时 ...
- Oracle高级查询,over 用法
注:标题中的红色order by是说明在使用该方法的时候必须要带上order by. 一.rank()/dense_rank() over(partition by ...order by ...) ...
随机推荐
- 野火STM32 ADC独立模式单通道采集实验意外
1 //about calibration 2 //ADC_ResetCalibration(ADC1); 3 //while(ADC_GetResetCalibrationStatus(ADC1) ...
- 微信APP支付后台配置
1.申请商户号 ,申请成功后去配置证书APIv2 https://pay.weixin.qq.com/index.php/core/cert/api_cert#/ --MchKey 和MchI ...
- 增加select的option之间的间距
直接设置option的上下内边距即可,即padding-top和padding-bottom.
- 090_Java
在JAVA程序中,性能问题的大部分原因并不在于JAVA语言,而是程序本身.养成良好的编码习惯非常重要,能够显著地提升程序性能. ● 1. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载 ...
- Linux安装Nginx安装并配置stream
编译安装 1.下载可编译的nginx cd /opt wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -zxvf nginx-1.20.1 ...
- jmeter接口之json提取器应用
在接口测试中有一个这样的场景:业务接口需要用到登录token:下个接口需要用到前个接口返回值作为参数,该怎么实现? 首先先看下登录.业务接口,本文用的jmeter版本为5.4.1 一.json提取器设 ...
- 宝塔404 Not Found的解决方法-重启大法也适合服务器
本来以为服务器不是随时重启的,浪费了好几的时间配置ssl一直无法成功,后来处理404问题重启后,发现ssl也好使了. 以下引自连接 https://www.chichisvip.com/post/37 ...
- Kubernetes--容器重启策略和Pod终止过程
容器的重启策略 容器程序发生崩溃或容器申请超出限制的资源等原因都可能会导致Pod对象的终止,此时是否应该重建该Pod对象则取决于其重启策咯(restartPolicy)属性的定义. 1)Always: ...
- 常用得cron表达式
0 10 0 1 * ? //每月1号的0:10:00执行 0 01 00 28-31 * ? #月底最后一天早上凌晨1点执行 异常: 查询是否有特殊字符: cat -A ***.sh 解决方法: 1 ...
- CSP202104-4 校门外的树
设状态时,首先从简单状态设起: 一维不行再试二维.简单状态应付不了再设复杂的(因为某些状态可以体现在状态转移的过程中,或者说状态转移方程中,不一定体现在原式中) E.g. 计算机软件能力认证考试系统- ...
AQ_ADMINISTRATOR_ROLE