Module: Cloudenvoy

Defined in:
lib/cloudenvoy.rb,
lib/cloudenvoy/topic.rb,
lib/cloudenvoy/config.rb,
lib/cloudenvoy/engine.rb,
lib/cloudenvoy/message.rb,
lib/cloudenvoy/testing.rb,
lib/cloudenvoy/version.rb,
lib/cloudenvoy/publisher.rb,
lib/cloudenvoy/subscriber.rb,
lib/cloudenvoy/subscription.rb,
lib/cloudenvoy/authenticator.rb,
lib/cloudenvoy/logger_wrapper.rb,
lib/cloudenvoy/pub_sub_client.rb,
lib/cloudenvoy/middleware/chain.rb,
lib/cloudenvoy/publisher_logger.rb,
lib/cloudenvoy/subscriber_logger.rb,
lib/cloudenvoy/authentication_error.rb,
lib/cloudenvoy/backend/google_pub_sub.rb,
lib/cloudenvoy/backend/memory_pub_sub.rb,
lib/cloudenvoy/invalid_subscriber_error.rb,
lib/generators/cloudenvoy/publisher_generator.rb,
lib/generators/cloudenvoy/subscriber_generator.rb,
app/controllers/cloudenvoy/subscriber_controller.rb

Overview

Define and manage Cloud Pub/Sub publishers and subscribers

Defined Under Namespace

Modules: Authenticator, Backend, Generators, Middleware, Publisher, Subscriber, Testing Classes: AuthenticationError, Config, Engine, InvalidSubscriberError, LoggerWrapper, Message, PubSubClient, PublisherLogger, SubscriberController, SubscriberLogger, Subscription, Topic

Constant Summary collapse

VERSION =
'0.6.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



26
27
28
# File 'lib/cloudenvoy.rb', line 26

def config=(value)
  @config = value
end

Class Method Details

.configCloudenvoy::Config

Return the Cloudenvoy configuration.

Returns:



40
41
42
# File 'lib/cloudenvoy.rb', line 40

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Cloudenvoy configurator.

Yields:



31
32
33
# File 'lib/cloudenvoy.rb', line 31

def self.configure
  yield(config)
end

.loggerLogger

Return the Cloudenvoy logger.

Returns:

  • (Logger)

    The Cloudenvoy logger.



49
50
51
# File 'lib/cloudenvoy.rb', line 49

def self.logger
  config.logger
end

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

Publish a message to a topic. Shorthand method to Cloudenvoy::PubSubClient#publish.

Parameters:

  • topic (String)

    The name of the topic

  • payload (Hash, String)

    The message content.

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

    The message attributes.

Returns:



62
63
64
# File 'lib/cloudenvoy.rb', line 62

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

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

Publish multiple messages to a topic. Shorthand method to Cloudenvoy::PubSubClient#publish_all.

Parameters:

  • topic (String)

    The name of the topic

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

    A list of message [payload, metadata].

Returns:



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

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

.publishersSet<Cloudenvoy::Subscriber>

Return the list of registered publishers.

Returns:



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

def self.publishers
  @publishers ||= Set.new
end

.setup_publishersArray<Cloudenvoy::Subscription>

Create/update default topics for all registered publishers.

Returns:



110
111
112
# File 'lib/cloudenvoy.rb', line 110

def self.setup_publishers
  publishers.flat_map(&:setup)
end

.setup_subscribersArray<Cloudenvoy::Subscription>

Create/update subscriptions for all registered subscribers.

Returns:



101
102
103
# File 'lib/cloudenvoy.rb', line 101

def self.setup_subscribers
  subscribers.flat_map(&:setup)
end

.subscribersSet<Cloudenvoy::Subscriber>

Return the list of registered subscribers.

Returns:



92
93
94
# File 'lib/cloudenvoy.rb', line 92

def self.subscribers
  @subscribers ||= Set.new
end