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.



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

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.



191
192
193
194
195
196
197
198
199
# File 'lib/leopard/nats_api_server.rb', line 191

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:



204
205
206
207
# File 'lib/leopard/nats_api_server.rb', line 204

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.



210
211
212
213
214
215
216
# File 'lib/leopard/nats_api_server.rb', line 210

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