1

我正在尝试通过服务使用 ODP.NET 将来自 oracle AQ 的消息出列

一旦 Service Dequeue 消息,该记录不应该可用于其他服务实例,这意味着它应该被锁定直到事务提交或事务过期

我的问题是我能够成功地将记录出列,但消息状态没有从就绪状态更新到任何其他状态,我也能够获取有效负载数据

 Public Shared Sub DequeueMessage(ByVal MessageID As String)
        Dim constr As String = "mystring"
        Dim con As Oracle.DataAccess.Client.OracleConnection = New Oracle.DataAccess.Client.OracleConnection(constr)
        Dim queue As OracleAQQueue = New OracleAQQueue("MyQueuname", con)

        Try
            con.Open()
            Dim oracleCommand As OracleCommand = New OracleCommand("Select MSGID  from INTEGRATION_MSG_QUEUE where msgid='B85439241C9241A4A6B1869F08F382E7'", con)
            Dim K = oracleCommand.ExecuteScalar()
            Dim rawBytesFromOracle As Byte() = TryCast(K, Byte())
            Dim txn As Oracle.DataAccess.Client.OracleTransaction = con.BeginTransaction()
            queue.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit
            queue.DequeueOptions.Wait = 0
            queue.DequeueOptions.DequeueMode = OracleAQDequeueMode.Locked
            queue.DequeueOptions.MessageId = rawBytesFromOracle
            queue.MessageType = OracleAQMessageType.Udt
            queue.UdtTypeName = "TRIGGER_AUDIT_TYPE"
            Dim deqMsg As OracleAQMessage = queue.Dequeue()
            Dim data As TRIGGER_AUDIT_TYPE = CType(deqMsg.Payload, TRIGGER_AUDIT_TYPE)
            Console.WriteLine("Dequeued message...." & data.CMESSAGEBODY) ''Iam getting data here
            txn.Commit()
        Catch e As Exception
            Console.WriteLine("Error: {0}", e.Message)
        Finally
            con.Close()
            con.Dispose()
        End Try
    End Sub

我的队列就像

BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE(
     Queue_table        => '"instance"."INTEGRATION_MSG_QUEUE"',
     Queue_payload_type => '"instance"."TRIGGER_AUDIT_TYPE"',
     Sort_list          => 'ENQ_TIME',
     Compatible         => '10.0.0',
     primary_instance   => 3,
     secondary_instance => 2);
  END;
  
   BEGIN DBMS_AQADM.CREATE_QUEUE(
     Queue_name          => '"instance"."INTEGRATION_MSG_QUEUE_Q"',
     Queue_table         => '"instance"."INTEGRATION_MSG_QUEUE"',
     Queue_type          =>  0,
     Max_retries         =>  5,
     Retry_delay         =>  0,
     dependency_tracking =>  FALSE);
  END;

有人可以建议我做错了什么

4

1 回答 1

0

您需要使用以下命令将其出队:

queue.DequeueOptions.DequeueMode = OracleAQDequeueMode.Remove

或者:

queue.DequeueOptions.DequeueMode = OracleAQDequeueMode.RemoveNoData

当您使用Locked模式时,您只是在浏览并获得对消息的锁定。您需要实际更新它。

请参阅: https ://docs.oracle.com/cd/E11882_01/win.112/e23174/OracleAQDequeueModeEnumeration.htm#ODPNT3687

于 2021-02-28T14:59:55.290 回答