dapr 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 729104779716640e3712c3a0330bcd374e7adef6b2b3fb4913e6835a90c37ad5
4
- data.tar.gz: 120496be092ef9a626b78bffd367922f23055791e92644e5af62aa3cf874bd2b
3
+ metadata.gz: 6d5c9d0a5f1e7de3748c6b53613b68418e1330787b61210ab7af54d37763f502
4
+ data.tar.gz: 027e810589e9b23cca2bcfe615fdcbbe5775c9b32c1e61194ed7de08feabe9f9
5
5
  SHA512:
6
- metadata.gz: 86377d8383fee71ebce7aa7838ff68c070a9f07ca4f66dceed5c8790f45edfaf4dde52edc05723713e9e9f8416b9c59aa0b5a349679468a31f057d5019ce774f
7
- data.tar.gz: 111ec36f62186ea6e98d6460591b735083da02c791b77383567027ba62c90f6cc38677021cb2057a3341ac7a68b648a78b8cc813185c0ef757af0d54871f2224
6
+ metadata.gz: ee6a4cc2d02ff17c66c0dc9ef91f10e6f032e13f41a9025e67af4238868c507b06469d95fd7e9a84d420ce9f9fef7404528c1d4307c912d9dfb5f2cc6ab81721
7
+ data.tar.gz: 1c76f27f7c9774e1987b74f57092a4fca991dc400ed94b63500c550926956887c2f82e915758658c073ec2e881b8fa1e2b4d44ac372fb35ac7062cf141d2efb0
@@ -10,8 +10,8 @@ module Rubyists
10
10
  # Include the client module
11
11
  include Client
12
12
 
13
- # The name of the pubsub component, and the client
14
- attr_reader :pubsub_name, :client
13
+ # The name of the pubsub component, the client, and the serialization to use
14
+ attr_reader :pubsub_name, :client, :serialization
15
15
 
16
16
  # The proto class for the publish event request
17
17
  Proto = ::Dapr::Proto::Runtime::V1::PublishEventRequest
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../service'
4
+
5
+ $stdout.sync = true
6
+
7
+ module Rubyists
8
+ module Dapr
9
+ module Service
10
+ # The Subscriber class is a simple implementation of a Dapr subscriber service.
11
+ class Subscriber
12
+ include SemanticLogger::Loggable
13
+
14
+ attr_reader(:service_proto, :runtime_proto, :pubsub_name, :topics, :event_handler)
15
+
16
+ Port = ENV.fetch('DAPR_GRPC_APP_PORT', 50_051)
17
+
18
+ def initialize(pubsub_name:,
19
+ topics:,
20
+ handler: nil,
21
+ service_proto: Dapr::Proto::Runtime::V1::AppCallback::Service,
22
+ runtime_proto: Dapr::Proto::Runtime::V1)
23
+ @topics = Array(topics)
24
+ @pubsub_name = pubsub_name
25
+ @service_proto = service_proto
26
+ @runtime_proto = runtime_proto
27
+ @handler = handler
28
+ end
29
+
30
+ def handle_event!(topic_event, topic_call)
31
+ return handler&.call(topic_event, topic_call) if handler.respond_to?(:call)
32
+
33
+ logger.warn('Unhandled event: event handler does not respond to #call',
34
+ topic_event:,
35
+ topic_call:,
36
+ handler:)
37
+ end
38
+
39
+ def subscriptions
40
+ @subscriptions ||= topics.map do |topic|
41
+ runtime_proto::TopicSubscription.new(pubsub_name:, topic:)
42
+ end
43
+ end
44
+
45
+ def service # rubocop:disable Metrics/MethodLength
46
+ return @service if @service
47
+
48
+ subscriber = self
49
+ @service = Class.new(service_proto) do
50
+ define_method(:on_topic_event) do |topic_event, topic_call|
51
+ subscriber.handle_event!(topic_event, topic_call)
52
+ Google::Protobuf::Empty.new
53
+ end
54
+ define_method(:list_topic_subscriptions) do |_empty, _call|
55
+ subscriber.runtime_proto::ListTopicSubscriptionsResponse.new(subscriptions: subscriber.subscriptions)
56
+ end
57
+ end
58
+ end
59
+
60
+ def start!
61
+ server = GRPC::RpcServer.new
62
+ server.add_http2_port("0.0.0.0:#{Port}", :this_port_is_insecure)
63
+ server.handle(service)
64
+ log.warn('Starting Dapr Subscriber service', port: Port)
65
+ server.run_till_terminated_or_interrupted([1, +'int', +'SIGQUIT'])
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/dapr/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubyists
4
4
  module Dapr
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.8'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tj (bougyman) Vanderpoel
@@ -54,6 +54,7 @@ files:
54
54
  - lib/dapr.rb
55
55
  - lib/dapr/client.rb
56
56
  - lib/dapr/client/publisher.rb
57
+ - lib/dapr/service/subscriber.rb
57
58
  - lib/dapr/version.rb
58
59
  - sig/dapr.rbs
59
60
  homepage: https://github.com/rubyists/dapr