• Oracle高级排队机制


     

    子程序

    说明

    DBMS_AQ

    ENQUEUE

    enqueueE操作,向队列中插入消息,带有指定的路由传递信息

    DBMS_AQ

    DEQUEUE

    Dequeue操作,从队列中检索出消息,带有指定的选项消息

    DBMS_AQADM

    CREATE_QUEUE_TABLE

    用指定的参数创建列表

    DBMS_AQADM

    CREATE_QUEUE

    在现有队列表中创建一个队列

    DBMS_AQADM

    DROP_QUEUE

    从队列表中删除指定队列

    DBMS_AQADM

    DROP_QUEUE_TABLE

    删除队列表,以及其组件队列

    DBMS_AQADM

    ALTER_QUEUE

    更改给定队列的选项

    DBMS_AQADM

    ADD_SUBSCRIBER

    向指定队列中添加预约者

    DBMS_AQADM

    REMOVE_SUBSCRIBER

    从给定队列中删除预约者

    DBMS_AQADM

    GRANT_TYPE_ACCESS

    为队列管理器授予权限

    DBMS_AQADM

    QUEUE_SUBSCRIBERS

    返回指定队列的预约者

    DBMS_AQADM

    START_TIME_MANAGER

    启动时间管理器后台进程

    DBMS_AQADM

    STOP_TIME_MANAGER

    停止时间管理器后台进程

    DBMS_AQ支持类型

    类型名

    说明

    用于

    SYS.AQ$_AGENT

    消息的生产者或消费者

    作为AQ$_RECIPIENT_LIST_T的一部分被包含,因此用于ENQUEUETDEQUEUE

    AQ$RECIPIENT_LIST_T

    接收消息的代理列表

    作为MESSAGE_PROPERIES_T的一部分被包含,因此用于ENQUEUEDEQUEUE

    MESSAGE_PROPERTIES_T

    消息的属性

    ENQUEQUDEQUEUE

    ENQUEUE_OPTIONS_T

    Enqueue的选项

    ENQUEQU

    DEQUEUE_OPTIONS_T

    Dequeue的选项

    DEQUEUE

    1.      SYS.AQ$_AGENT

    TYPE SYS.AQ$_AGENT IS RECORD

    (

     Name varchar2(30),

     Address varchar2(30),

     Protocol number

    )

    2.      AQ$RECIPIENT_LIST_T

    Type aq$_recipient_list_t is table of sys.aq$_agent index by binary_integer;

    3.      MESSAGE_PROPERTIES_T

    Type message_properties_t is record

    (

     Priority binary_integer default 1,

     Delay binary_integer default no_delay,

     Expiration binary_integer default never,

     Correlation varchar2(128) default null,

      Attempts binary_integer,

     Recipient_list aq$_recipient_list_t,

     Exception_queue varchar2(50) default null,

     Enqueue_time date,

     State binary_integer

    )

    参数说明:

    字段

    数据类型

    说明

    Priority

    Binary_integer

    相应消息的优先级,比较小的数字意味着比较高的优先级,优先级可以是任何整数,其中也包括负数

    Delay

    Binary_integer

    相应消息的延迟.delay可以是NO_DELAY(这意味着消息可以被立即从队列中取出),或者要等待的秒数.指定消息标识符的dequeue操作将忽略该延迟而进行操作.被延迟的消息在执行enqueue(插入队列)操作时的状态是waiting,然后在delay秒以后变为ready状态

    Expiration

    Binary_integer

    过期的秒数,如果该消息还没有被从队列中取出,那么该消息将不会过期.如果指定了过期时间,过期时间是在延迟以后开始计算的.在过期以后,该消息被移动到异常队列中,此时的状态是expired

    Correlation

    Varchar2(128)

    关联标识符.如果需要的话,可以按照关联标识符检索消息

    Attempts

    Binary_integer

    尝试提取该消息的次数.这个参数仅仅用于dequeue

    Recipient_list

    Aq$recipient_list_t

    此消息的接收都列表.此参数在enqueue执行时被读出,而在dequeu操作时并不返回它

    Exception_queue

    Varchar2(51)

    此消息的异常队列.如果消息过期或者queue操作的次数超过了max_retres,那么该消息就被移动到异常队列中,其状态为expired.如果没有指定exception_queue,那么该消息就被移动到队列表的缺省异常队列中.如果指定了exception_queue但是在移动时此队列不定期是无效的,那么该消息将被移动到队列表的缺省异常队列中,同时该消息也被写入警报日志中

    Enqueue_time

    Date

    消息插入队列的时间.这个参数将被dequeue返回,在执行enqueue操作时它自动被系统所设定

    State

    Binary_integer

    在执行dequeue操作时消息的状态.这个参数不能由enqueue所设定,它会被系统自动进行更新.其取值为waiting(消息延迟还滑到达)ready(消息已准备被处理)processed(消息已被处理,但是还保留在队列中)expired(消息已被移动到异常队列中)

    4.      ENQUEUE_OPTIONS_T

    Type enqueue_option_t is record

    (

     Visibility binary_integer default no_commit,

     Relative_msgid raw(16) default null,

     Sequence_deviation binary_integer default null

    )

    参数说明:

    字段

    数据类型

    说明

    Visibility

    Binary_integer

    指定事务的行为。如果visibilityon_commit,那么当当前事务提交以后该enqueue将完成。如果visibilityimmediate时,那么enqueue将构建一个单独的立即被提交的事务。即使当前事务被撤消了,该enqueue操作也将会执行

    Relative_msgid

    Raw

    如果在sequeue_deviation中指定了before,那么在由relative_msgid所标识的消息的前面会插入此消息。如果没有指定sequence_deviation,那么将忽略relative_msgid

    Sequence_deviation

    Binary_integer

    指定在队列中此消息的位置。有效的取值为before(该消息将被插入到由relative_msgid所标识的消息的前面)top(该消息将被插入到所有其他消息的前面)以及NULL(该消息的优先级指定了在队列中它的位置)。缺省值是NULL

    5.      DEQUEUE_OPTIONS_T

    Type dequeue_options_t is record

    (

     Consumer_name varchar2(30) default null,

     Dequeue_mode binary_integer default null remove,

     Navigation binary_integer default next_message,

     Visibility binary_integer default on_commit,

     Wait binary_integer default forever,

    Msgid raw(16) default null

    )

    参数说明:

    字段

    数据类型

    说明

    Consumer_name

    Varchar2(30)

    接收该消息的消费者名字。如果指定了,队列中只有匹配此消费者的消息才会被处理。如果该队列没有设置为供多个消费者所用,那么consumer_name应该是NULL

    Dequeue_mode

    Binary_integer

    指定dequeue操作的锁定行为。有效取值是browse(读出消息同时并不加锁和从队列中删除消息,这类似于select)locked(读出消息并得到关于该消息的一个写操作锁,这类似于select for update)以及remove(读出该消息,然后更新或删除该消息,这要取决于该队列的保留特性)Remove是缺省值

    Navigation

    Binary_integer

    指定要检索的消息的位置。在决定了该位置以后,搜索条件(包括consumer_namemsgidcorrelation)就会被应用。有效的取值是next_message(检索匹配搜索条件的下一个消息)next_transaction(如果当前的消息组中还有剩余的消息就跳过它们检索匹配条件)

    Visibility

    Binary_integer

    指定是否dequeue是当前事务的一部分,如果是on_commit(缺省值),那么dequeue操作就是当前事务的一部分。如果是immediate,那么dequeue操作是其自身的一个事务,该事务会立即被提交

    Wait

    Binary_integer

    指定如果当前没有匹配搜索条件的消息时等待的秒数,如果同一个组中的消息正被执行dequeue操作,那么这个参数就会被忽略。有效取值是forever(没有超时,这是缺省设置)no_wait(不等待,如果没有所需要的消息则立即返回)或者要等待的秒数。

    Msgid

    Raw(16)

    指定要执行dequeue操作的消息标识符

    Correlation

    Varchar2(30)

    指定要执行dequeue操作的关联标识符

    枚举常量

    DBMS_AQ中支持类型的许多字段都是枚举常量。这此字段被定义为binary_integer,DBMS_AQ定义相应的取值。在设置了这些选项以后,它们需要使用其包名作为前缀,例如:DBMS_AQ.IMMEDIATE.下面的表列出了所有枚举常量,它们的取值以及它们用在何处.

    字段

    取值

    使用位置

    Sequeue_deviation

    Before,top

    Enqueue_options_t

    Visibility

    Immediate,on_commit

    Enqueue_options_t

    Dequeue_mode

    Browse,locked,remove

    Dequeue_options_t

    Navigation

    First_message,next_message,next_transaction

    Dequeue_options_t

    Wait

    Forever,no_wait

    Dequeue_options_t

    State

    Waiting,ready,processed,expired

    Message_properties_t

    Delay

    No_delay

    Message_properties_t

    Expiration

    Never

    Message_properties_t

    过程定义:

    .Enqueue

    Procedure enqueue(

     Queue_name in varchar2,

     Enqueue_options in enqueue_options_t,

     Message_properties in message_properties_t,

     Payload in message_type,

     Msgid out raw);

    参数说明:

    字段

    数据类型

    说明

    Queue_name

    Varchar2

    应该插入消息的队列

    Enqueue_options

    Enqueue_options_t

    Enqueue的选项.

    Message_properties

    Message_properties_t

    消息的属性,这些属性将会在下一个dequeue操作中返回

    Payload

    Message_type

    消息数据.这可能是raw类型或对象类型.如果它是对象类型,那么它必须匹配在创建时指定的类型

    Msgid

    Raw

    返回的消息ID.这个ID可以用来对此特定的消息执行dequeue操作,无论优先级或延迟是多少.

    Enqueue选项的sequeue_deviation字段指定了在两个消息之间的关系.如果指定了这个字段,那么对于被插入队列的消息的延迟和优先级有两个限制:

    1. 新插入队列的消息延迟必须少于或者等于在此消息被插入队列以前的消息延迟.
    2. 新插入队列的消息的优先级必须大于或者等于在此消息被插入队列以前的消息的优先级.

    .dequeue

    Procedure dequeue(

     Queue_name in varchar2,

     dequeue_options in enqueue_options_t,

     Message_properties in message_properties_t,

     Payload in message_type,

     Msgid out raw);

    Dequeue的搜索条件是由consumer_name,msgid/dequeue_optionscorrelation字段决定的.如果没有指定msgid,那么只有ready状态的消息会从队列中被删除.

    .create_queue_table

    Create_queue_table用于创建队列表,并指定稍后在本表上创建的队列的缺省属性,其中包括队列的排序次序.

    a.       与此队列表相关联的缺省异常队列,称为aq$_queue_table_e.

    b.       可以用于查询队列的只读视图,称为aq$_queue_table.

    c.       时间管理所用的索引,称为aq$_queue_table_t.

    d.       多个消费者队列的索引,称为aq$_queue_table_i.

    Procedure create_queue_table(

     Queue_table in varchar2,

     Queue_payload_type in varchar2,

     Storage_clause in varchar2 default null,

     Sort_list in varchar2 default null,

     Multiple_consumers in Boolean default false,

     Message_grouping in binary_integer default none,

     Commet in varchar2 default null,

     Auto_commit in Boolean default true);

    参数

    数据类型

    说明

    Queue_table

    Varchar2

    要创建的队列表的名字

    Queue_payload_type

    Varchar2

    此队列中的用户数据的类型,它应该是raw或对象类型的

    Storage_clause

    Varchar2

    用在create table 语句中的存储参数.

    Sort_list

    Varchar2

    定义用作排序主键的列,这样就可以对这个表中创建的队列进行排序了.

    Multiple_consumers

    Boolean

    如果为true在此表中创建的队列可以对每个消息拥有多个消费者,该用户必须要首先使用grant_type_access被授予类型访问权限.如果为false(缺省值),那么在此表中创建的队列只能对一个消息有一个消费者.

    Message_grouping

    Binary_integer

    如果为NONE(缺省值),那么在此队列表中创建的队列中每个消息被单独进行处理.如果是transactional,那么作为一个事务的一部分而被插入所有的消息都被认为是同一个消息组的一部分,这样就会同时从队列中删除了

    Comment

    Varchar2

    新创建的表的注释.它将被记录到队列目录中

    Auto_commit

    Boolean

    如果是true(缺省值),当前事务在队列表被创建以前被提交,create_queue_table返回时该操作生效.如果为false,那么创建操作是当前事务的一部分,并将在当前事务提交时该操作生效

    .Drop_queue_table(

     Queue_table in varchar2,

     Force in Boolean default false,

     Auto_commit in Boolean default true);

    参数说明:

     Force:如果为true,该表中的所有队列都自动停止并被删除.如果是false,那么如果在表中仍有队列会返回一个错误

    .Create_queue

    在指定的队列表中创建一个队列.队列名必须在当前数据模式中是唯一的,缺省情况下,对该队列的enqueuedequeue操作是被屏蔽的.在创建了该队列以后,必须使用start_queue来使得enqueuedequeue操作生效.

    Procedure create_queue(

     Queue_name in varchar2,

     Queue_table in varchar2,

     Queue_type in binary_integer default normal_queue,

     Max_retries in number default 0,

     Retry_delay in number default 0,

     Retention_time in number default 0,

     Dependency_tracking in Boolean default false,

     Comment in varchar2 default null,

     Auto_commit in Boolean default true);

    参数说明:

    参数

    数据类型

    说明

    Queue_name

    Varchar2

    要创建的队列的名字

    Queue_table

    Varchar2

    将要包含新创建的队列的队列表.

    Queue_type

    Binary_integer

    队列类型,有效取值是normal_queue(创建通常的队列)exception_queue(创建异常队列)

    Max_retries

    Number

    尝试dequeue操作(指定remove)的最大次数,如果一个代理从队列中删除消息,但是稍后又撤消了其事务,那么计数值也会增加.当计数值到达了max_retries,该消息会被移动到异常队列中.

    Retry_delay

    Number

    在两次尝试之间的秒数.如果max_retries是以,那么retry_delay就不起作用.如果该队列有多个消息者,那么就不能指定retry_delay

    Retention_time

    Number

    消息在被执行dequeue以后在队列表中保留的秒数.有效值是infinite(该消息将被永远保留)或一定的秒数.default 0

    Dependency_tracking

    Boolean

    该参数被保留用作将来之用

    Comment

    Varchar2

    对新创建的队列的说明,此注释将被添加到队列目录中

    Auto_commit

    Boolean

    如果为true,那么在该队列被创建以前当前是会被提交,create_queue返回时该操作会生效,如果是false,那么当当前事务提交时该操作将生效

    六.Drop_queue

    从队列中删除一个已存在的队列。在被删除以前,该队列必须使用STOP_QUEUE予以停止。在执行此操作时,所有的队列数据都将被删除。

    Procedure drop_queue(

     Queue_name in varchar2,

     Auto_commit in Boolean default true);

    七.Alter_queue

    此过程用于修改队列的某些属性。只有max_retries,retry_delayretention_time属性可以被修改。如果要改变其他属性,那么该队列必须要被删除并重新生成。

    Procedure alter_queue(

     Queue_name in varchar2,

     Max_retries in number default null,

     Retry_delay in number default null,

     Retention_time in number default null,

     Auto_commit in Boolean default true);

    参数

    数据类型

    说明

    Queue_name

    Varchar2

    要修改的队列的名字

    Max_retries

    Number

    尝试dequeue操作(指定remove)的最大次数.如果一个代理从队列中删除消息,但是稍后又撤消了其事务,那么计数值也会增加.当计数值到达了max_retries,该消息会被移动到异常队列中

    Retry_delay

    Number

    在两次尝试之间的秒数,如果max_retries0,那么retry_delay就不起作用.如果该队列有多个消费者,那么就不能指定retry_delay

    Retention_time

    Number

    消息在被执行dequeue以后在队列表中保留的秒数,有效值是infinite(该消息将被永远保留)或一定的秒数.缺省值是0

    Auto_commit

    Boolean

    如果是true,那么在该队列被创建以前当前是会被提交.alter_queue返回时该操作会生效,如果是false,那么当当前事务提交时该操作将生效

    .Start_queue

    用于使得对一个队列运行进行enqueue/dequeue操作.在创建以后,队列必须使用此函数启动.对于异常对象进行dequeue操作,所以对于异常队列来打开允许enqueue操作的设置是不起作用的.在此过程返回时该队列被启动,甚至即使该事务撤消了.

    Procedure start_queue(

     Queue_name in varchar2,

     Enqueue in Boolean default true,

     Dequeue in Boolean default true);

    Enqueue,dequeue分别指定了该队列应该允许执行enqueuedequeue操作.

    .Stop_queue

    用于对指定队列进行屏蔽enqueue/dequeue操作.如果对队列正在执行事务时,是不能停止该队列的.当该过程返回时此队列会被停止使用 ,甚至即使该事务撤消了

    Procedure stop_queue(

     Queue_name in varchar2,

     Enqueue in Boolean default true,

     Dequeue in Boolean default true,

    Wait in Boolean default true);

    如果waittrue,那么此调用将被阻塞直到所有针对queue_name的事务被提交或被撤消为止.如果是false,那么stop_queue将立即返回成功或是失败.

    .Add_subscriber

    将向队列中添加一个缺省的预约者,这仅对拥有多个消费者的队列是有效的.Add_subscriber会立即生效,并且当前的事务会提交.用户通过Grant_type_acces必须被授予访问此队列的权限

    Procedure add_subscriber(

     Queue_name in varchar2,

     Subscriber in sys.aq$_agent);

    Subscriber是新的预约者.

    十一.Remove_subscriber

    此过程将从指定的队列中删除指定预约者, Remove_subscriber会立即生效,并且当前的事务会提交.用户通过Grant_type_acces必须被授予访问此队列的权限

    Procedure Remove_subscriber(

     Queue_name in varchar2,

     Subscriber in sys.aq$_agent);

    十二.queue_subscribers

    此函数指定队列的预约者的PL/SQL

    Function queue_subscribers(

     Queue_name in varchar2)

     Return aq$_subscriber_list_t;

    十三.Grant_type_access

    Grant_type_access用于使得一个用户能够执行队列管理操作.如果不使用该过程,那么用户将不能执行Create_queue_table,Create_queue,Add_subscriberremove_subscriber

    Procedure grant_type_access(

     User_name in varchar2);

    User_name 是要被授予权限的数据库用户

    十四.Start_time_manager

    此过程启动时间管理进程.AQ_TM_PROCESS init.ora参数必须先被设置为1,这会在数据库启动的时候启动该进程.当这个调用返回的时候,时间管理器被启动,即使当前的事务被撤销,无参数.

    Procedure start_time_manager;

    十五.Stop_time_manager

    使得时间管理器失效.但是,它不终止该进程,它只是使得该进程停止其工作,当此调用返回时,时间管理器将被停止,即使当前的事务被撤销了.

    Procedure stop_time_manager;

  • 相关阅读:
    startx
    BIOS above 4g setting
    How to download file from google drive
    凤凰财经
    SOTA state-of-the-art model
    update gpu drivers
    /opt/nvidia/deepstream/deepstream/sources/libs/nvdsinfer_customparser/nvdsinfer_custombboxparser.cpp
    retinanet keras
    fp16 fp32 int8
    tf.gather with tf.Session() as sess:
  • 原文地址:https://www.cnblogs.com/jimeper/p/972986.html
Copyright © 2020-2023  润新知