1

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?

abi
  • 99
  • 8

1 Answers1

1

Sorry for the delay. You are using 2 different subjects, which means in NATS Streaming that messages will go to different channels. You can't expect delivery to an application to be in any specific order. If messages are sent to the same channel, then the order messages are published from the single threaded producer will be the same order that the streaming server sends to its consumers.

I. Kozlovic
  • 796
  • 3
  • 3