Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
leopard (0.2.2)
leopard (0.2.3)
concurrent-ruby (~> 1.1)
dry-configurable (~> 1.3)
dry-monads (~> 1.9)
Expand Down Expand Up @@ -53,7 +53,7 @@ GEM
racc (1.8.1)
rainbow (3.1.1)
rake (13.3.0)
regexp_parser (2.11.0)
regexp_parser (2.11.2)
reline (0.6.2)
io-console (~> 0.5)
rubocop (1.79.2)
Expand Down Expand Up @@ -91,7 +91,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
unicode-display_width (3.1.4)
unicode-display_width (3.1.5)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.3)
Expand Down
16 changes: 13 additions & 3 deletions examples/echo_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@
class EchoService
include Rubyists::Leopard::NatsApiServer

config.logger = SemanticLogger[:EchoService]
def initialize(a_var: 1)
logger.info "EchoService initialized with a_var: #{a_var}"
end

endpoint(:echo) { |msg| Success(msg.data) }
endpoint(:echo_fail) { |msg| Failure({ failure: '*boom*', data: msg.data }) }
endpoint(:echo) do |msg|
data = msg.data
logger.trace('Received message', data:)
Success(data)
end
endpoint(:echo_fail) do |msg|
data = msg.data
logger.trace('Received message', data:)
Failure({ failure: '*boom*', data: msg.data })
end
end

if __FILE__ == $PROGRAM_NAME
SemanticLogger.default_level = :info
SemanticLogger.add_signal_handler
SemanticLogger.add_appender(io: $stdout, formatter: :color)
EchoService.run(
nats_url: 'nats://localhost:4222',
Expand All @@ -25,6 +35,6 @@ def initialize(a_var: 1)
version: '1.0.0',
instance_args: { a_var: 2 },
},
instances: 1,
instances: ENV.fetch('ECHO_INSTANCES', '1').to_i,
)
end