Skip to content

Examples

The examples are intentionally short. They show the API the gem is expected to support without turning each file into a test harness.

Source: examples/core_lifecycle.rb

Terminal window
bundle exec ruby examples/core_lifecycle.rb

Shows NatsAsync::Client, explicit start(task:), a subscription callback, one publish, and close in ensure.

Source: examples/queue_group.rb

Terminal window
bundle exec ruby examples/queue_group.rb

Shows subscribe(subject, queue:) and drain(timeout:) for a worker-style subscriber.

Source: examples/request_reply.rb

Terminal window
bundle exec ruby examples/request_reply.rb

Shows a service publishing to message.reply, async request callbacks, and a message-oriented request promise with wait.data.

Source: examples/headers_and_binary.rb

Terminal window
bundle exec ruby examples/headers_and_binary.rb

Shows NATS headers through HPUB / HMSG and byte-preserving payload handling.

Source: examples/jetstream_management.rb

Terminal window
bundle exec ruby examples/jetstream_management.rb

Shows add_stream?, stream_exists?, add_consumer?, and consumer_info.

Source: examples/jetstream_publish.rb

Terminal window
bundle exec ruby examples/jetstream_publish.rb

Shows js.publish returning a publish acknowledgement with stream and seq.

Source: examples/jetstream_pull_consumer.rb

Terminal window
bundle exec ruby examples/jetstream_pull_consumer.rb

Shows durable pull subscription setup, fetch(batch:, timeout:), and message ack/nak.

Source: examples/backend_detection.rb

Terminal window
bundle exec ruby examples/backend_detection.rb

Shows client.resolve_backend(mode: :auto, stream:) selecting :jetstream when the stream exists and falling back to :core otherwise.

Source: examples/jetstream_roundtrip.rb

Terminal window
bundle exec ruby examples/jetstream_roundtrip.rb

Shows stream creation, durable pull subscription, publish ack, fetch, message metadata, ack, and cleanup.