Module: Propono

Defined in:
lib/propono.rb,
lib/propono/utils.rb,
lib/propono/logger.rb,
lib/propono/version.rb,
lib/propono/configuration.rb,
lib/propono/propono_error.rb,
lib/propono/components/sns.rb,
lib/propono/components/sqs.rb,
lib/propono/components/queue.rb,
lib/propono/components/topic.rb,
lib/propono/services/publisher.rb,
lib/propono/services/subscriber.rb,
lib/propono/components/aws_config.rb,
lib/propono/services/tcp_listener.rb,
lib/propono/services/udp_listener.rb,
lib/propono/components/sqs_message.rb,
lib/propono/services/queue_creator.rb,
lib/propono/services/topic_creator.rb,
lib/propono/services/queue_listener.rb,
lib/propono/components/post_subscription.rb,
lib/propono/components/queue_subscription.rb

Overview

Propono is a pub/sub gem built on top of Amazon Web Services (AWS). It uses Simple Notification Service (SNS) and Simple Queue Service (SQS) to seamlessly pass messages throughout your infrastructure.

Defined Under Namespace

Modules: Sns, Sqs, Subscriber, Utils Classes: AwsConfig, Configuration, Logger, PostSubscription, ProponoConfigurationError, ProponoError, Publisher, PublisherError, Queue, QueueCreator, QueueCreatorError, QueueListener, QueueSubscription, SqsMessage, TcpListener, TcpListenerError, Topic, TopicCreator, TopicCreatorError, UdpListener, UdpListenerError

Constant Summary collapse

VERSION =
"1.6.0"

Class Method Summary collapse

Class Method Details

.aws_optionsObject



3
4
5
# File 'lib/propono/components/aws_config.rb', line 3

def self.aws_options
  AwsConfig.new(Propono.config).aws_options
end

.configObject

Propono configuration settings.

Settings should be set in an initializer or using some other method that insures they are set before any Propono code is used. They can be set as followed:

Propono.config.access_key = "my-access-key"

The following settings are allowed:

  • :access_key - The AWS access key

  • :secret_key - The AWS secret key

  • :queue_region - The AWS region

  • :application_name - The name of the application Propono is included in.

  • :queue_suffix - Optional string to append to topic and queue names.

  • :udp_host - If using UDP, the host to send to.

  • :udp_port - If using UDP, the port to send to.

  • :logger - A logger object that responds to puts.



51
52
53
54
55
56
57
58
# File 'lib/propono.rb', line 51

def self.config
  @config ||= Configuration.new
  if block_given?
    yield @config
  else
    @config
  end
end

.drain_queue(topic, &message_processor) ⇒ Object

Listens on a queue and yields for each message

Calling this will enter a queue-listening loop that yields the message_processor for each messages. The loop will end when all messages have been processed.

This method will automatically create a subscription if one does not exist, so there is no need to call subscribe_by_queue in addition.

Parameters:

  • topic (String)

    The topic to subscribe to.

  • &message_processor

    The block to yield for each message.



122
123
124
# File 'lib/propono.rb', line 122

def self.drain_queue(topic, &message_processor)
  QueueListener.drain(topic, &message_processor)
end

.listen_to_queue(topic, &message_processor) ⇒ Object

Listens on a queue and yields for each message

Calling this will enter a queue-listening loop that yields the message_processor for each messages.

This method will automatically create a subscription if one does not exist, so there is no need to call subscribe_by_queue in addition.

Parameters:

  • topic (String)

    The topic to subscribe to.

  • &message_processor

    The block to yield for each message.



106
107
108
# File 'lib/propono.rb', line 106

def self.listen_to_queue(topic, &message_processor)
  QueueListener.listen(topic, &message_processor)
end

.listen_to_tcp(&message_processor) ⇒ Object

Listens for TCP messages and yields for each.

Calling this will enter a queue-listening loop that yields the message_processor for each UDP message received.

Parameters:

  • &message_processor

    The block to yield for each message. Is called with |topic, message|.



144
145
146
# File 'lib/propono.rb', line 144

def self.listen_to_tcp(&message_processor)
  TcpListener.listen(&message_processor)
end

.listen_to_udp(&message_processor) ⇒ Object

Listens for UDP messages and yields for each.

Calling this will enter a queue-listening loop that yields the message_processor for each UDP message received.

Parameters:

  • &message_processor

    The block to yield for each message. Is called with |topic, message|.



133
134
135
# File 'lib/propono.rb', line 133

def self.listen_to_udp(&message_processor)
  UdpListener.listen(&message_processor)
end

.proxy_tcpObject

Listens for TCP messages and passes them onto the queue.

This method uses #listen_to_tcp and #publish to proxy messages from TCP onto the queue.



162
163
164
165
166
# File 'lib/propono.rb', line 162

def self.proxy_tcp
  Propono.listen_to_tcp do |topic, message, options = {}|
    Propono.publish(topic, message, options)
  end
end

.proxy_udpObject

Listens for UDP messages and passes them onto the queue.

This method uses #listen_to_udp and #publish to proxy messages from UDP onto the queue.



152
153
154
155
156
# File 'lib/propono.rb', line 152

def self.proxy_udp
  Propono.listen_to_udp do |topic, message, options = {}|
    Propono.publish(topic, message, options)
  end
end

.publish(topic, message, options = {}) ⇒ Object

Publishes a new message into the Propono pub/sub network.

This requires a topic and a message. By default this pushes out AWS SNS. The method optionally takes a :protocol key in options, which can be set to :udp for non-guaranteed but very fast delivery.

Parameters:

  • topic (String)

    The name of the topic to publish to.

  • message (String)

    The message to post.

  • options (Hash) (defaults to: {})
    • protocol: :udp



71
72
73
74
# File 'lib/propono.rb', line 71

def self.publish(topic, message, options = {})
  suffixed_topic = "#{topic}#{Propono.config.queue_suffix}"
  Publisher.publish(suffixed_topic, message, options)
end

.subscribe_by_post(topic, endpoint) ⇒ Object

Creates a new SNS-POST subscription on the specified topic.

The POST currently needs confirming before the subscription can be published to.

Parameters:

  • topic (String)

    The name of the topic to subscribe to.



91
92
93
# File 'lib/propono.rb', line 91

def self.subscribe_by_post(topic, endpoint)
  Subscriber.subscribe_by_post(topic, endpoint)
end

.subscribe_by_queue(topic) ⇒ Object

Creates a new SNS-SQS subscription on the specified topic.

This is implicitly called by #listen_to_queue.

Parameters:

  • topic (String)

    The name of the topic to subscribe to.



81
82
83
# File 'lib/propono.rb', line 81

def self.subscribe_by_queue(topic)
  Subscriber.subscribe_by_queue(topic)
end