Class: Fog::Google::Pubsub::Subscription
- Inherits:
-
Model
- Object
- Model
- Fog::Google::Pubsub::Subscription
- Defined in:
- lib/fog/google/models/pubsub/subscription.rb
Overview
Represents a Pubsub subscription resource
Instance Method Summary collapse
-
#acknowledge(messages) ⇒ Object
Acknowledges a list of received messages for this subscription.
-
#destroy ⇒ Object
Deletes this subscription on the remote service.
-
#pull(options = { :return_immediately => true, :max_messages => 10 }) ⇒ Array<Fog::Google::Pubsub::ReceivedMessage>
Pulls from this subscription, returning any available messages.
-
#save ⇒ Fog::Google::Pubsub::Subscription
Save this instance on the remove service.
Instance Method Details
#acknowledge(messages) ⇒ Object
Acknowledges a list of received messages for this subscription.
55 56 57 58 59 60 61 62 |
# File 'lib/fog/google/models/pubsub/subscription.rb', line 55 def acknowledge() return if .empty? ack_ids = .map { |m| m.is_a?(ReceivedMessage) ? m.ack_id : m.to_s } service.acknowledge_subscription(name, ack_ids) nil end |
#destroy ⇒ Object
Deletes this subscription on the remote service.
78 79 80 81 82 |
# File 'lib/fog/google/models/pubsub/subscription.rb', line 78 def destroy requires :name service.delete_subscription(name) end |
#pull(options = { :return_immediately => true, :max_messages => 10 }) ⇒ Array<Fog::Google::Pubsub::ReceivedMessage>
Pulls from this subscription, returning any available messages. By default, this method returns immediately with up to 10 messages. The option ‘return_immediately’ allows the method to block until a message is received, or the remote service closes the connection.
Note that this method automatically performs a base64 decode on the ‘data’ field.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/google/models/pubsub/subscription.rb', line 30 def pull( = { :return_immediately => true, :max_messages => 10 }) requires :name data = service.pull_subscription(name, ).to_h return [] unless data.key?(:received_messages) # Turn into a list of ReceivedMessage, but ensure we perform a base64 decode first data[:received_messages].map do || attrs = { :service => service, :subscription_name => name }.merge() attrs[:message][:data] = Base64.decode64([:message][:data]) if [:message].key?(:data) ReceivedMessage.new(attrs) end end |
#save ⇒ Fog::Google::Pubsub::Subscription
Save this instance on the remove service.
68 69 70 71 72 73 |
# File 'lib/fog/google/models/pubsub/subscription.rb', line 68 def save requires :name, :topic data = service.create_subscription(name, topic, push_config, ack_deadline_seconds).to_h merge_attributes(data) end |