java - Messages order for 2 different subscriptions
问题描述
I have following (simplified) setup
Consumer (single threaded, streamingConnection is singleton)
val streamingConnection by instance<StreamingConnection>()
streamingConnection.subscribe(Topics.OUTPUT_ORDER, OrderHandler())
streamingConnection.subscribe(Topics.OUTPUT_TRANSACTION, TransactionHandler())
Producer (single threaded, streamingConnection is singleton)
- Publishes message to Topics.OUTPUT_ORDER
- Publishes message to Topics.OUTPUT_TRANSACTION
Is nats streaming garantees, that consumer receives and handles messages in the same order? I have order id in transaction payload and I must know the id before transaction processing.
From nats java library description:
The new version minimizes threads. Only one thread is used for all callbacks, by relying on a dispatcher in the underlying NATS connection.
If there is only one thread, Topics.OUTPUT_TRANSACTION processing on consumer will be blocked until Topics.OUTPUT_ORDER onMessage() handler finishes. Am I right?
解决方案
抱歉耽搁了。您正在使用 2 个不同的主题,这意味着在 NATS Streaming 中消息将进入不同的频道。您不能期望以任何特定顺序交付给应用程序。如果消息被发送到同一个通道,那么从单线程生产者发布的消息顺序将与流服务器发送给其消费者的顺序相同。
推荐阅读
- javascript - Angular scrollPositionRestoration 仅偶尔在 Chrome 中有效
- mysql - 当我将代码从 sql 重写为 ruby 时执行查询
- jmeter - 在 JMeter 中写入 CSV 文件
- database - Deno 中的 MongoDB 模式索引
- azure - 为什么我在 Azure 容器实例中的 Selenium Grid 需要相同的时间来执行测试,而不管节点的数量是多少?
- javascript - 构建flutter mobile时可以使用js包吗?
- java - 仅在 ARM 64 shell 中发现的 Java
- mongodb - 如何在 mongodb 中应用字符串排序
- python - 预期类型'collections.Iterable',得到'RasterImageExtensions'
- linux - 有人可以追踪分段错误的原因吗?