class

NATS::Service

Inherits Reference / Object

The Service represents a NATS service that was created by the Services API. It exists to hang your endpoints on:

inventory = nats.services.add "inventory",
  version: "0.1.0",
  description: "Manage inventory"
inventory.add_endpoint "inventory.products.get", subject: "inventory.products.get.*" do |request|
  _, _, _, id
  nats.reply request, ProductQuery.new.find(id).to_json
end

Instance methods

add_endpoint(name : String, *, subject : String = name, queue_group : String = "q", concurrency : Int = 1, &block : Message, Subscription -> ) : Endpoint
service.add_endpoint "endpoint-name", subject: "endpoint.subject" do |request|
  nats.reply request, "reply goes here"
end
Source
add_group(name : String, &)

Add a Group and yield it to the block.

service.add_group "products" do |inventory|
  inventory.add_endpoint "create" do |request|
    nats.reply request, "reply goes here"
  end
end
Source
add_group(name : String)

Add a Group of endpoints.

Source
description
Source
endpoints
Source
error_reply(request : Message, body : String | Bytes = "", *, error : String, error_code : String | Int) : Nil
Source
metadata
Source
name
Source
on_error

Execute the given block for all exceptions raised in this service's endpoints. This is useful for returning a common error response.

service.on_error do |exception, message|
  nats.reply message, "", headers: NATS::Headers{
    "Nats-Service-Error-Code" => "500",
    "Nats-Service-Error"      => "Unexpected error: #{exception.message}",
  }
end
Source
subscriptions
Source
version
Source

Nested types