Skip to content

Commit 121dcef

Browse files
bougymanCopilot
andauthored
docs: Adds an example showing how to use groups (nested) (#32)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bougyman <6848+bougyman@users.noreply.github.com>
1 parent 6337118 commit 121dcef

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

examples/groups.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require_relative '../lib/leopard/nats_api_server'
5+
6+
# Example to echo the given message
7+
class ServiceGroups
8+
include Rubyists::Leopard::NatsApiServer
9+
10+
def initialize(a_var: 1)
11+
logger.info "ServiceGroups initialized with a_var: #{a_var}"
12+
end
13+
14+
group :mammal
15+
group :feline, group: :mammal, queue: :meow
16+
endpoint(:sound, group: :feline) { |msg| Success("Meow! #{msg.data}") }
17+
endpoint(:fail, group: :feline) { |msg| Failure({ reason: 'cat nap', data: msg.data }) }
18+
end
19+
20+
if __FILE__ == $PROGRAM_NAME
21+
SemanticLogger.default_level = :info
22+
SemanticLogger.add_appender(io: $stdout, formatter: :color)
23+
ServiceGroups.run(
24+
nats_url: 'nats://localhost:4222',
25+
service_opts: {
26+
name: 'example.groups',
27+
version: '1.0.0',
28+
instance_args: { a_var: 2 },
29+
},
30+
instances: 1,
31+
)
32+
end

0 commit comments

Comments
 (0)