nats-io / nats-pure.rb

Ruby client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
131 stars 30 forks source link

Add support for consumer multiple filters and streams/consumers metadata #138

Closed wallyqs closed 11 months ago

wallyqs commented 11 months ago

Examples:

# Creating a stream with multiple subjects
js.add_stream(name: "MULTI_FILTER", subjects: ["foo.one.*", "foo.two.*", "foo.three.*"])

# PullSubscriber that takes an array and creates a consumer with multiple filters .
js.pull_subscribe(["foo.one.1", "foo.two.2"], "example")

# PushSubscriber that takes an array and creates a consumer with multiple filters .
js.subscribe(["foo.one.1", "foo.three.3"])

# via JetStream#add_consumer API
consumer = js.add_consumer("MULTI_FILTER", {
       name: "my-consumer",
       filter_subjects: ["foo.one.*", "foo.two.*"]
})

# Pass nil to both subject and durable consumer name to bind to already created consumer
js.pull_subscribe(nil, nil, name: "my-consumer", stream: "MULTI_FILTER")

# Stream with metadata
stream = js.add_stream({
    :name     => "WITH_METADATA",
    :metadata => {
      'foo': 'bar',
      'hello': 'world'
    }
})