Oracle Advanced Queue 的消息状态在使用 ODP.net 出队后未更新
Posted
技术标签:
【中文标题】Oracle Advanced Queue 的消息状态在使用 ODP.net 出队后未更新【英文标题】:Message State of Oracle Advanced Queue not updating after Dequeue using ODP.net 【发布时间】:2020-08-12 05:37:34 【问题描述】:我正在尝试通过服务使用 ODP.NET 将来自 oracle AQ 的消息出列
一旦服务出列消息,该记录不应该可用于其他服务实例,这意味着它应该被锁定直到事务提交或事务过期
我的问题是我能够成功地将记录出列,但消息状态没有从就绪状态更新到任何其他状态,我也能够获取有效负载数据
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;
有人可以建议我做错了什么
【问题讨论】:
【参考方案1】:您需要使用以下命令将其出队:
queue.DequeueOptions.DequeueMode = OracleAQDequeueMode.Remove
或:
queue.DequeueOptions.DequeueMode = OracleAQDequeueMode.RemoveNoData
当您使用Locked
模式时,您只是在浏览并获得对消息的锁定。您需要实际更新它。
见: https://docs.oracle.com/cd/E11882_01/win.112/e23174/OracleAQDequeueModeEnumeration.htm#ODPNT3687
【讨论】:
以上是关于Oracle Advanced Queue 的消息状态在使用 ODP.net 出队后未更新的主要内容,如果未能解决你的问题,请参考以下文章
Oracle Advanced Queuing 之03(订阅&通知)
Machine Learning with Oracle Database Advanced Analytics
Oracle AQ c#并在c#中从oracle队列中使消息出队
PAT (Advanced Level) 1029. Median (25)