hanami-events-cloud_pubsub 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hanami/events/adapter/cloud_pubsub.rb +12 -12
- data/lib/hanami/events/cloud_pubsub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de5b89251e969ff280f708bfe2453b6f182b3bca5e50bfd98b9e8be372123562
|
4
|
+
data.tar.gz: d71ccf32872fae21acb045a8786b7935f051f92a25ff47ad6ff1340a0c88d44a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7740508a3898f859a59fbb39377bb2d6977ec06f48cf2671d177aa647c355945b50209a3b0b3c6815d1222424df7d998a83bb9402b0918118636c8fe053776fb
|
7
|
+
data.tar.gz: dd52a0e85056371712d695c6a2fd9650c49d5dfdaaff2c2afdf41cced04e61b2a12633eb2ee185eaa23dd15c40dcbfebef021ec92e14cdcdfa985de5951e7edd
|
@@ -11,13 +11,12 @@ module Hanami
|
|
11
11
|
#
|
12
12
|
# @api private
|
13
13
|
class CloudPubsub
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :listeners, :topic_registry, :middleware
|
15
15
|
|
16
16
|
def initialize(params)
|
17
17
|
@pubsub = params[:pubsub]
|
18
18
|
@logger = params[:logger] || Logger.new($stdout)
|
19
19
|
@listen = params[:listen] || false
|
20
|
-
@subscribers = Concurrent::Array.new
|
21
20
|
@listeners = Concurrent::Array.new
|
22
21
|
@serializer_type = params.fetch(:serializer, :json).to_sym
|
23
22
|
@topic_registry = {}
|
@@ -61,10 +60,9 @@ module Hanami
|
|
61
60
|
logger.debug("Subscribed listener \"#{id}\" for event \"#{event_name}\"")
|
62
61
|
|
63
62
|
sub = Hanami::Events::CloudPubsub::Subscriber.new(event_name, block, logger)
|
64
|
-
@subscribers << sub
|
65
63
|
topic = topic_for event_name
|
66
64
|
|
67
|
-
register_listener(event_name, topic, namespaced_id, auto_ack, subscriber_opts)
|
65
|
+
register_listener(event_name, topic, namespaced_id, auto_ack, subscriber_opts, sub)
|
68
66
|
end
|
69
67
|
|
70
68
|
def flush_messages
|
@@ -76,11 +74,12 @@ module Hanami
|
|
76
74
|
|
77
75
|
attr_reader :logger
|
78
76
|
|
79
|
-
|
77
|
+
# rubocop:disable Metrics/ParameterLists
|
78
|
+
def register_listener(event_name, topic, subscriber_id, auto_ack, subscriber_opts, sub)
|
80
79
|
listener = ::Hanami::Events::CloudPubsub::Listener.new(
|
81
80
|
subscriber_id: subscriber_id,
|
82
81
|
event_name: event_name,
|
83
|
-
handler:
|
82
|
+
handler: call_subscriber(sub),
|
84
83
|
logger: logger,
|
85
84
|
topic: topic,
|
86
85
|
subscriber_opts: subscriber_opts,
|
@@ -91,14 +90,15 @@ module Hanami
|
|
91
90
|
@listeners << listener
|
92
91
|
listener.register
|
93
92
|
end
|
93
|
+
# rubocop:enable Metrics/ParameterLists
|
94
94
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
def call_subscriber(sub)
|
96
|
+
proc do |message|
|
97
|
+
data = message.data
|
98
|
+
payload = serializer.deserialize(data)
|
99
|
+
event_name = message.attributes['event_name']
|
99
100
|
|
100
|
-
|
101
|
-
subscriber.call(event_name, payload, message)
|
101
|
+
sub.call(event_name, payload, message)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|