0

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?

4

1 回答 1

0

抱歉耽搁了。您正在使用 2 个不同的主题,这意味着在 NATS Streaming 中消息将进入不同的频道。您不能期望以任何特定顺序交付给应用程序。如果消息被发送到同一个通道,那么从单线程生产者发布的消息顺序将与流服务器发送给其消费者的顺序相同。

于 2020-03-11T17:17:39.613 回答