pubsub_client 1.5.0 → 2.0.0

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: 03ba6e12917979bfedb1b0d4aeade60f2ce675c561e99d57ace0b0850abb0f24
4
- data.tar.gz: e0628ab5d8c8183c95a1a438be7e32964870d891d7ded108bf5ce4eb10f63c5d
3
+ metadata.gz: 4efa5b8b5abeff4f0dd13ee6d945c8f733b0b3b46dac6528fcf4bd527a5f08a5
4
+ data.tar.gz: c69aa4f023b2af7fbfe44c7021650026b7a31d2e49f5e543741b213fbb53d005
5
5
  SHA512:
6
- metadata.gz: 4dafd9b8a6da6055d4d10bba716eb54d72fb6202b84ed693c090a9a53aa16c43ec6306fc641943f207da575bab6922fade8780536392f2f6c5231c7f88dc1558
7
- data.tar.gz: 2f975bcc3d71fb66d9031be80929b0e709d0605e7596039274e4591b7ab36f83c5f70b67a49d4aebb2adac1a3d75588595bf787a2c4f7e1fdec45078f708d176
6
+ metadata.gz: c4d38c468281279004e4504fe4a01b31652937b57270b0d63ce5930da8fefc82ec5d1ad2c12f5d0921001e12c460d0fe9e808c5fdaf1c790f47d4556ee7ed4b7
7
+ data.tar.gz: a7586ca0100862cb137627e110ffcae41e46d775645ef88622c6e594746eac636f7e7be67cb68ebffebfd0c899a5e7bd9bd79281e72a2ed3534fd3b49c7817df
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,8 @@
1
+ Version 2.0.0 2021-03-30
2
+ ------------------------
3
+ 172dc19 Add support for multiple clients
4
+ 3525193 Update subscriber example to include name of subscription instead of …
5
+
1
6
  Version 1.5.0 2020-11-05
2
7
  ------------------------
3
8
  6cab366 Do not require GAC when stubbed
data/README.md CHANGED
@@ -22,11 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  In order to use this gem, the environment variable `GOOGLE_APPLICATION_CREDENTIALS` must be set and point to the credentials JSON file.
24
24
 
25
- If there are environments where setting up credentials is too burdensome and/or publishing messages is not desired, `PubsubClient` can be stubbed out with `PubsubClient.stub!`, e.g.
25
+ If there are environments where setting up credentials is too burdensome and/or publishing messages is not desired, `PubsubClient` can be stubbed out with `.stub!`, e.g.
26
26
 
27
27
  ```ruby
28
+ @client = PubsubClient.new
29
+
28
30
  if test_env?
29
- PubsubClient.stub!
31
+ @client.stub!
30
32
  end
31
33
  ```
32
34
 
@@ -34,11 +36,11 @@ end
34
36
 
35
37
  ### Publishing
36
38
 
37
- To publish a message to Pub/Sub, call `PubsubClient.publish(message, 'the-topic')`. This method takes any serializable object as an argument and yields a result object to a block. The `result` object has a method `#succeeded?` that returns `true` if the message was successfully published, otherwise `false`. In the latter case, there is a method `#error` that returns the error.
39
+ To publish a message to Pub/Sub, call `@client.publish(message, 'the-topic')`. This method takes any serializable object as an argument and yields a result object to a block. The `result` object has a method `#succeeded?` that returns `true` if the message was successfully published, otherwise `false`. In the latter case, there is a method `#error` that returns the error.
38
40
 
39
41
  #### Example
40
42
  ```ruby
41
- PubsubClient.publish(message, 'some-topic') do |result|
43
+ @client.publish(message, 'some-topic') do |result|
42
44
  if result.succeeded?
43
45
  puts 'yay!'
44
46
  else
@@ -55,7 +57,7 @@ Optionally, a client can choose to handle exceptions raised by the subscriber. I
55
57
 
56
58
  #### Example
57
59
  ```ruby
58
- subscriber = PubsubClient.subscriber('some-topic')
60
+ subscriber = @client.subscriber('some-subscription')
59
61
 
60
62
  subscriber.listener(concurrency: 4, auto_ack: false) do |data, received_message|
61
63
  # Most clients will only need the first yielded arg.
data/lib/pubsub_client.rb CHANGED
@@ -1,48 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pubsub_client/version'
2
4
  require 'pubsub_client/null_publisher_factory'
3
5
  require 'pubsub_client/null_subscriber_factory'
4
6
  require 'pubsub_client/publisher_factory'
5
7
  require 'pubsub_client/subscriber_factory'
6
8
 
7
- module PubsubClient
9
+ class PubsubClient
8
10
  Error = Class.new(StandardError)
9
11
  ConfigurationError = Class.new(Error)
10
12
  CredentialsError = Class.new(Error)
11
13
  InvalidTopicError = Class.new(Error)
12
14
  InvalidSubscriptionError = Class.new(Error)
13
15
 
14
- class << self
15
- def stub!
16
- raise ConfigurationError, 'PubsubClient is already configured' if @publisher_factory || @subscriber_factory
17
- @publisher_factory = NullPublisherFactory.new
18
- @subscriber_factory = NullSubscriberFactory.new
19
- @stubbed = true
20
- end
16
+ def stub!
17
+ raise ConfigurationError, 'PubsubClient is already configured' if @publisher_factory || @subscriber_factory
21
18
 
22
- # @param message [String] The message to publish.
23
- # @param topic [String] The name of the topic to publish to.
24
- def publish(message, topic, attributes = {}, &block)
25
- ensure_credentials!
19
+ @publisher_factory = NullPublisherFactory.new
20
+ @subscriber_factory = NullSubscriberFactory.new
21
+ @stubbed = true
22
+ end
26
23
 
27
- @publisher_factory ||= PublisherFactory.new
28
- @publisher_factory.build(topic).publish(message, attributes, &block)
29
- end
24
+ # @param subscription [String] - The name of the subscription to subscribe to.
25
+ def subscriber(subscription)
26
+ ensure_credentials!
27
+
28
+ @subscriber_factory ||= SubscriberFactory.new
29
+ @subscriber_factory.build(subscription)
30
+ end
30
31
 
31
- # @param subscription [String] - The name of the topic to subscribe to.
32
- def subscriber(subscription)
33
- ensure_credentials!
32
+ def publish(message, topic, attributes = {}, &block)
33
+ ensure_credentials!
34
34
 
35
- @subscriber_factory ||= SubscriberFactory.new
36
- @subscriber_factory.build(subscription)
37
- end
35
+ @publisher_factory ||= PublisherFactory.new
36
+ @publisher_factory.build(topic).publish(message, attributes, &block)
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :stubbed, :publisher_factory, :subscriber_factory
38
42
 
39
- private
43
+ def ensure_credentials!
44
+ return if defined?(stubbed) && stubbed
40
45
 
41
- def ensure_credentials!
42
- return if defined?(@stubbed) && @stubbed
43
- unless ENV['GOOGLE_APPLICATION_CREDENTIALS']
44
- raise CredentialsError, 'GOOGLE_APPLICATION_CREDENTIALS must be set'
45
- end
46
+ unless ENV['GOOGLE_APPLICATION_CREDENTIALS']
47
+ raise CredentialsError, 'GOOGLE_APPLICATION_CREDENTIALS must be set'
46
48
  end
47
49
  end
48
50
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PubsubClient
3
+ class PubsubClient
4
4
  # A null object to act as a publisher when clients are in dev or test
5
5
  class NullPublisher
6
6
  # This is required so that this publisher maintains the same contract
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'null_publisher'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  # A null object to act as a publisher factory when clients are in dev or test
7
7
  class NullPublisherFactory
8
8
  def build(*)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PubsubClient
3
+ class PubsubClient
4
4
  # A null object to act as a subscriber when clients are in dev or test
5
5
  class NullSubscriber
6
6
  # This adds a subset of the available methods on the
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'null_subscriber'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  # A null object to act as a subscriber factory when clients are in dev or test
7
7
  class NullSubscriberFactory
8
8
  def build(*)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'google/cloud/pubsub'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  class Publisher
7
7
  # @param topic [Google::Cloud::PubSub::Topic]
8
8
  def initialize(topic)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'publisher'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  # Build and memoize the Publisher, accounting for GRPC's requirements around forking.
7
7
  class PublisherFactory
8
8
  def initialize
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'google/cloud/pubsub'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  class Subscriber
7
7
  DEFAULT_CONCURRENCY = 8
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'subscriber'
4
4
 
5
- module PubsubClient
5
+ class PubsubClient
6
6
  class SubscriberFactory
7
7
  def initialize
8
8
  @subscribers = {}
@@ -1,3 +1,3 @@
1
- module PubsubClient
2
- VERSION = '1.5.0'
1
+ class PubsubClient
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsub_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apartment List Platforms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake