Module: Rubyists::Leopard::NatsApiServer::InstanceMethods

Defined in:
lib/leopard/nats_api_server.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject

Returns the logger configured for the NATS API server.



184
# File 'lib/leopard/nats_api_server.rb', line 184

def logger = self.class.logger

#setup_worker(nats_url: 'nats://localhost:4222', service_opts: {}) ⇒ void

This method returns an undefined value.

Sets up a worker thread for the NATS API server. This method connects to the NATS server, adds the service, groups, and endpoints,

Parameters:

  • url (String)

    The URL of the NATS server.

  • opts (Hash)

    Options for the NATS service.

  • eps (Array<Hash>)

    The list of endpoints to add.

  • gps (Hash)

    The groups to add.



195
196
197
198
199
200
201
202
203
# File 'lib/leopard/nats_api_server.rb', line 195

def setup_worker(nats_url: 'nats://localhost:4222', service_opts: {})
  @thread  = Thread.current
  @client  = NATS.connect nats_url
  @service = @client.services.add(build_service_opts(service_opts:))
  gps = self.class.groups.dup
  eps = self.class.endpoints.dup
  group_map = add_groups(gps)
  add_endpoints eps, group_map
end

#setup_worker!(nats_url: 'nats://localhost:4222', service_opts: {}) ⇒ Object

Sets up a worker thread for the NATS API server and blocks the current thread.

See Also:



208
209
210
211
# File 'lib/leopard/nats_api_server.rb', line 208

def setup_worker!(nats_url: 'nats://localhost:4222', service_opts: {})
  setup_worker(nats_url:, service_opts:)
  sleep
end

#stopObject

Stops the NATS API server worker.



214
215
216
217
218
219
220
# File 'lib/leopard/nats_api_server.rb', line 214

def stop
  @service&.stop
  @client&.close
  @thread&.wakeup
rescue ThreadError
  nil
end