pubsub_client 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +5 -0
- data/README.md +7 -5
- data/lib/pubsub_client.rb +29 -27
- data/lib/pubsub_client/null_publisher.rb +1 -1
- data/lib/pubsub_client/null_publisher_factory.rb +1 -1
- data/lib/pubsub_client/null_subscriber.rb +1 -1
- data/lib/pubsub_client/null_subscriber_factory.rb +1 -1
- data/lib/pubsub_client/publisher.rb +1 -1
- data/lib/pubsub_client/publisher_factory.rb +1 -1
- data/lib/pubsub_client/subscriber.rb +1 -1
- data/lib/pubsub_client/subscriber_factory.rb +1 -1
- data/lib/pubsub_client/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4efa5b8b5abeff4f0dd13ee6d945c8f733b0b3b46dac6528fcf4bd527a5f08a5
|
4
|
+
data.tar.gz: c69aa4f023b2af7fbfe44c7021650026b7a31d2e49f5e543741b213fbb53d005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
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
|
-
|
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 =
|
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
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
@publisher_factory = NullPublisherFactory.new
|
20
|
+
@subscriber_factory = NullSubscriberFactory.new
|
21
|
+
@stubbed = true
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
ensure_credentials!
|
32
|
+
def publish(message, topic, attributes = {}, &block)
|
33
|
+
ensure_credentials!
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
43
|
+
def ensure_credentials!
|
44
|
+
return if defined?(stubbed) && stubbed
|
40
45
|
|
41
|
-
|
42
|
-
|
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,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '
|
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:
|
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:
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|