Class: Cloudenvoy::PubSubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudenvoy/pub_sub_client.rb

Overview

Interface to publishing backend (GCP, emulator or memory backend)

Class Method Summary collapse

Class Method Details

.backendModule<Cloudenvoy::Backend::MemoryPubSub, Cloudenvoy::Backend::GoogleCloudTask>

Return the backend to use for sending messages.

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cloudenvoy/pub_sub_client.rb', line 11

def self.backend
  # Re-evaluate backend every time if testing mode enabled
  @backend = nil if defined?(Cloudenvoy::Testing)

  @backend ||= begin
    if defined?(Cloudenvoy::Testing) && Cloudenvoy::Testing.in_memory?
      require 'cloudenvoy/backend/memory_pub_sub'
      Backend::MemoryPubSub
    else
      require 'cloudenvoy/backend/google_pub_sub'
      Backend::GooglePubSub
    end
  end
end

.publish(topic, payload, attrs = {}) ⇒ Cloudenvoy::Message

Publish a message to a topic.

Parameters:

  • topic (String)

    The name of the topic

  • payload (Hash, String)

    The message content.

  • attrs (Hash) (defaults to: {})

    The message attributes.

Returns:



35
36
37
# File 'lib/cloudenvoy/pub_sub_client.rb', line 35

def self.publish(topic, payload, attrs = {})
  backend.publish(topic, payload, attrs)
end

.publish_all(topic, msg_args) ⇒ Array<Cloudenvoy::Message>

Publish multiple messages to a topic.

Parameters:

  • topic (String)

    The name of the topic

  • msg_args (Array<Array<[Hash, String]>>)

    A list of message [payload, metadata].

Returns:



47
48
49
# File 'lib/cloudenvoy/pub_sub_client.rb', line 47

def self.publish_all(topic, msg_args)
  backend.publish_all(topic, msg_args)
end

.upsert_subscription(topic, name, opts = {}) ⇒ Cloudenvoy::Subscription

Create or update a subscription for a specific topic.

Parameters:

  • topic (String)

    The name of the topic

  • name (String)

    The name of the subscription

  • opts (Hash) (defaults to: {})

    The subscription configuration options

Options Hash (opts):

  • :deadline (Integer)

    The maximum number of seconds after a subscriber receives a message before the subscriber should acknowledge the message.

  • :retain_acked (Boolean)

    Indicates whether to retain acknowledged messages. If true, then messages are not expunged from the subscription’s backlog, even if they are acknowledged, until they fall out of the retention window. Default is false.

  • :retention (<Type>)

    How long to retain unacknowledged messages in the subscription’s backlog, from the moment a message is published. If retain_acked is true, then this also configures the retention of acknowledged messages, and thus configures how far back in time a Subscription#seek can be done. Cannot be more than 604,800 seconds (7 days) or less than 600 seconds (10 minutes). Default is 604,800 seconds (7 days).

  • :filter (String)

    An expression written in the Cloud Pub/Sub filter language. If non-empty, then only Message instances whose attributes field matches the filter are delivered on this subscription. If empty, then no messages are filtered out. Optional.

Returns:



73
74
75
# File 'lib/cloudenvoy/pub_sub_client.rb', line 73

def self.upsert_subscription(topic, name, opts = {})
  backend.upsert_subscription(topic, name, opts)
end

.upsert_topic(topic) ⇒ Cloudenvoy::Topic

Create or update a topic.

Parameters:

  • topic (String)

    The topic name.

Returns:



84
85
86
# File 'lib/cloudenvoy/pub_sub_client.rb', line 84

def self.upsert_topic(topic)
  backend.upsert_topic(topic)
end