Class: PubsubClient::Subscriber
- Inherits:
-
Object
- Object
- PubsubClient::Subscriber
- Defined in:
- lib/pubsub_client/subscriber.rb
Constant Summary collapse
- DEFAULT_CONCURRENCY =
8
Instance Method Summary collapse
-
#initialize(subscription) ⇒ Subscriber
constructor
A new instance of Subscriber.
-
#listener(concurrency: DEFAULT_CONCURRENCY, auto_ack: true, &block) ⇒ Google::Cloud::PubSub::Subscriber
to remove it from the topic.
- #on_error(&block) ⇒ Object
- #subscribe ⇒ Object
Constructor Details
#initialize(subscription) ⇒ Subscriber
Returns a new instance of Subscriber.
10 11 12 |
# File 'lib/pubsub_client/subscriber.rb', line 10 def initialize(subscription) @subscription = subscription end |
Instance Method Details
#listener(concurrency: DEFAULT_CONCURRENCY, auto_ack: true, &block) ⇒ Google::Cloud::PubSub::Subscriber
to remove it from the topic. Default is ‘true`.
19 20 21 22 23 24 25 26 |
# File 'lib/pubsub_client/subscriber.rb', line 19 def listener(concurrency: DEFAULT_CONCURRENCY, auto_ack: true, &block) @listener ||= begin @subscription.listen(threads: { callback: concurrency }) do || yield .data, .acknowledge! if auto_ack end end end |
#on_error(&block) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/pubsub_client/subscriber.rb', line 40 def on_error(&block) raise ConfigurationError, 'A listener must be configured' unless @listener @listener.on_error do |exception| yield exception end end |
#subscribe ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pubsub_client/subscriber.rb', line 28 def subscribe raise ConfigurationError, 'A listener must be configured' unless @listener begin @listener.start sleep rescue SignalException @listener.stop.wait! end end |