Module: Rubyists::Leopard::NatsApiServer::InstanceMethods
- Defined in:
- lib/leopard/nats_api_server.rb
Instance Method Summary collapse
-
#logger ⇒ Object
Returns the logger configured for the NATS API server.
-
#setup_worker(nats_url: 'nats://localhost:4222', service_opts: {}) ⇒ void
Sets up a worker thread for the NATS API server.
-
#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.
-
#stop ⇒ Object
Stops the NATS API server worker.
Instance Method Details
#logger ⇒ Object
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,
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.
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 |
#stop ⇒ Object
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 |