Oracle 高级队列中不相关消息的选择性出队
该问题涉及Oracle Streams Advanced Queueing中的消息出队。
我需要确保彼此相关的消息按顺序处理。
例如,假设队列中包含四个消息,这些消息具有称为事务引用 (txn_ref) 的业务相关字段,并且其中两个消息 (1,3) 属于同一事务 (000001):
id | txn_ref |
---+---------+
1 | 000001 |
2 | 000002 |
3 | 000001 |
4 | 000003 |
还假设我正在运行4 个线程/进程希望从此队列中出队。应该发生以下情况:
- 线程 1 将消息 #1 出列,
- 线程 2 将消息 #2 出列,
- 线程 3 将消息 #4 出列(因为消息 #3 与 #1 相关,并且 #1 尚未完成)。
- 线程 4 阻塞等待消息
- 线程 1 提交消息 #1 的工作
- 线程 4(或者线程 1)将消息 #3 出列。
我最初的想法是,我可以通过出队条件来实现此目的,其中 ENQ_TIME(入队时间)不晚于具有相同 TXN_REF 的所有消息的任何其他 ENQ_TIME。但我的问题是如何引用我尚未选择的消息的 TXN_REF 以便选择它。例如,
// Java API
String condition = "ENQ_TIME = (select min(ENQ_TIME) from AQ_TABLE1 where ??";
dequeueOption.setCondition(condition);
这里可以实现我想要的吗?
This question refers to the dequeueing of messages in Oracle Streams Advanced Queueing.
I need to ensure that the messages which are related to each other are processed sequentially.
For example, assume the queue is seeded with the four messages that have a business-related field called transaction reference (txn_ref) and two of the messages (1,3) belong to the same transaction (000001):
id | txn_ref |
---+---------+
1 | 000001 |
2 | 000002 |
3 | 000001 |
4 | 000003 |
Assume also that I am running 4 threads/processes that wish to dequeue from this queue. The following should occur:
- thread 1 dequeues message #1
- thread 2 dequeues message #2
- thread 3 dequeues message #4 (because message #3 is related to #1 and #1 has not yet completed).
- thread 4 blocks waiting for a message
- thread 1 commits its work for message #1
- thread 4 (or perhaps thread 1) dequeues message #3.
My initial thought was that I could achieve this with a dequeue condition where the ENQ_TIME (enqueue time) is not later than any other ENQ_TIME of all the messages that have the same TXN_REF. But my problem is how to reference the TXN_REF of a message that I have not yet selected, in order to select it. e.g.
// Java API
String condition = "ENQ_TIME = (select min(ENQ_TIME) from AQ_TABLE1 where ??";
dequeueOption.setCondition(condition);
Is it possible to achieve what I want here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答您的直接问题,可以使用专为此目的而设计的
correlation
字段(表中称为CORRID
)来实现。因此,在排队时,您可以使用
AQMessageProperties.setCorrelation()
方法并将 TXN_REF 值作为参数。然后,根据你的情况,你会做这样的事情:To answer your direct question, this can be achieved using the
correlation
field (calledCORRID
in the table), which is designed for this purpose.So, on the enqueue, you'd use the
AQMessageProperties.setCorrelation()
method with the TXN_REF value as the parameter. Then, in your condition you would do something like this:如果可能的话,您可以尝试的一种策略是使用消息组。 Oracle 文档对此进行了简要描述,但我发现这篇蟾蜍世界文章是更有用。基本上,您设置队列表将同时提交的所有消息视为一个“组”。出队时,一次只有一个用户可以从一组消息中出队。
A strategy which you can try, if possible, is using Message Groups. The Oracle Documentation describes it briefly, but I found this Toad World article to be far more useful. Basically, you setup the queue table to treat all messages committed at the same time as one "group". When dequeueing, only one user at a time can dequeue from a "group" of messages.