其他架构不存在Oracle Advanced QUEUE

时间:2017-01-02 11:16:36

标签: plsql oracle12c advanced-queuing

我遇到了与此问题相同的问题:Grant permission to queues to another schema in oracle

但是给予其他用户权限根本不起作用。

我的队列:

   DBMS_AQADM.create_queue_table (
      queue_table          => 'event_queue_tab',
      queue_payload_type   => 't_event_queue_payload',
      multiple_consumers   => TRUE,
      comment              => 'Queue Table For Event Messages',
      secure => false);

   -- Create the event queue.
   DBMS_AQADM.create_queue (queue_name    => 'event_queue',
                            queue_table   => 'event_queue_tab');

   -- Start the event queue.
   DBMS_AQADM.start_queue (queue_name => 'event_queue');

此队列使用架构USER1创建。在这个模式中,我有一个包pkg1,当我调用它时它有一个过程,它的排队:

PROCEDURE proc1
   IS
      PRAGMA AUTONOMOUS_TRANSACTION;
      l_enqueue_options      DBMS_AQ.ENQUEUE_OPTIONS_T;
      l_message_properties   DBMS_AQ.MESSAGE_PROPERTIES_T;
      l_message_handle       RAW (16);
      l_queue_msg            t_event_queue_payload;
   BEGIN
      l_queue_msg := t_event_queue_payload ('give_me_a_prod');

      DBMS_AQ.enqueue (queue_name           => 'event_queue',
                       enqueue_options      => l_enqueue_options,
                       message_properties   => l_message_properties,
                       payload              => l_queue_msg,
                       msgid                => l_message_handle);
      COMMIT;
   EXCEPTION
      WHEN OTHERS
      THEN
         DBMS_OUTPUT.put_line (
            SQLERRM || ' - ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
   END proc1;

我有第二个架构USER2,它具有通过特定ROLE(ROLE1)执行pkg1的权限。但是当他调用proc1时,会收到下一个错误:

ORA-24010: QUEUE USER2.EVENT_QUEUE does not exist - ORA-06512: at "SYS.DBMS_AQ", line 180
ORA-06512: at "USER1.PKG1", line 1808

我在USER1中执行了此权限命令,但没有成功:

BEGIN
   DBMS_AQADM.grant_queue_privilege (privilege      => 'ALL',
                                     queue_name     => 'USER1.event_queue',
                                     grantee        => 'USER2',
                                     grant_option   => TRUE);
END;

我真的开始明白Ad.Queues是如何运作的。我在这里错过了什么吗?感谢。

EDIT1: 授予此队列的权限后授予:

SELECT grantee,
       owner,
       name,
       grantor,
       enqueue_privilege,
       dequeue_privilege
  FROM queue_privileges
 WHERE name = upper('event_queue');

ROLE1   USER1   EVENT_QUEUE USER1   1   1
USER2   USER1   EVENT_QUEUE USER1   1   1

1 个答案:

答案 0 :(得分:1)

只是一个猜测,它与同义词有关吗?因为USER2.QUEUE的错误消息不存在。也许它无法触及User1队列,因为在内部它试图在它自己的架构中找到它?尝试在过程中将队列名称作为user1.event_queue。

我的意思是:

PROCEDURE proc1
   IS
      PRAGMA AUTONOMOUS_TRANSACTION;
      l_enqueue_options      DBMS_AQ.ENQUEUE_OPTIONS_T;
      l_message_properties   DBMS_AQ.MESSAGE_PROPERTIES_T;
      l_message_handle       RAW (16);
      l_queue_msg            t_event_queue_payload;
   BEGIN
      l_queue_msg := t_event_queue_payload ('give_me_a_prod');

      DBMS_AQ.enqueue (queue_name           => 'user1.event_queue',
                       enqueue_options      => l_enqueue_options,
                       message_properties   => l_message_properties,
                       payload              => l_queue_msg,
                       msgid                => l_message_handle);
      COMMIT;
   EXCEPTION
      WHEN OTHERS
      THEN
         DBMS_OUTPUT.put_line (
            SQLERRM || ' - ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END proc1;

我为什么这么说?因为当您授予权限时,您会在event_queue之前明确提及架构USER1,并且该过程有效。但是在使用入队程序时却没有这样做。