class Natsy::Config::Options
A Natsy::Config::Options
object is passed as a single argument to the block (if provided) for the Natsy::Config::set
method. This class should probably NOT be instantiated directly; instead, set the relevant options using +Natsy::Config.set(some_option: “…”, some_other_option: “…”)+. If you find yourself instantiating this class directly, there's probably a better way to do what you're trying to do.
Attributes
Set a default queue for subscriptions.
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(default_queue: "foobar")
@example
Natsy::Config.set do |options| options.default_queue = "foobar" end
Leave the ::default_queue
blank (or assign nil
) to use no default queue.
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(default_queue: nil)
@example
Natsy::Config.set do |options| options.default_queue = nil end
Attach a logger to have natsy
write out logs for messages received, responses sent, errors raised, lifecycle events, etc.
NOTE: The following two examples do exactly the same thing.
@example
require 'natsy' require 'logger' nats_logger = Logger.new(STDOUT) nats_logger.level = Logger::INFO Natsy::Config.set(logger: nats_logger)
@example
require 'natsy' require 'logger' Natsy::Config.set do |options| nats_logger = Logger.new(STDOUT) nats_logger.level = Logger::INFO options.logger = nats_logger end
In a Rails application, you might do this instead:
@example
Natsy::Config.set(logger: Rails.logger)
Specify a NATS server URL (or multiple URLs)
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(url: "nats://foo.bar:4567"))
@example
Natsy::Config.set do |options| options.url = "nats://foo.bar:4567" end
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(urls: ["nats://foo.bar:4567", "nats://foo.bar:5678"])
@example
Natsy::Config.set do |options| options.urls = ["nats://foo.bar:4567", "nats://foo.bar:5678"] end
If left blank/omitted, natsy
will fall back on the default URL, which is nats://localhost:4222
.
Specify a NATS server URL (or multiple URLs)
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(url: "nats://foo.bar:4567"))
@example
Natsy::Config.set do |options| options.url = "nats://foo.bar:4567" end
NOTE: The following two examples do exactly the same thing.
@example
Natsy::Config.set(urls: ["nats://foo.bar:4567", "nats://foo.bar:5678"])
@example
Natsy::Config.set do |options| options.urls = ["nats://foo.bar:4567", "nats://foo.bar:5678"] end
If left blank/omitted, natsy
will fall back on the default URL, which is nats://localhost:4222
.
Public Instance Methods
{include:Natsy::Config::Options#default_queue}
# File lib/natsy/config.rb, line 112 def default_queue=(new_queue) @default_queue = Utils.presence(new_queue.to_s) Utils.log(logger, "Setting the default queue to #{@default_queue || '(none)'}", level: :debug) end
{include:Natsy::Config::Options#logger}
# File lib/natsy/config.rb, line 79 def logger=(new_logger) @logger = new_logger Utils.log(@logger, "Set the logger to #{@logger.inspect}", level: :debug) end
Returns ONLY the config options THAT HAVE BEEN SET as a Hash
. Will not have keys for properties that are unassigned, but will have keys for properties assigned nil
.
# File lib/natsy/config.rb, line 120 def to_h hash = {} hash[:url] = url if defined?(@url) hash[:urls] = urls if defined?(@urls) hash[:logger] = logger if defined?(@logger) hash[:default_queue] = default_queue if defined?(@default_queue) hash end