module Cloudenvoy::Backend::MemoryPubSub
Store messages in a memory queue. Used for testing
Public Instance Methods
Clear all messages in a specific topic.
@param [String] name The topic to clear.
@return [Array] The cleared array.
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 30 def clear(topic) queue(topic).clear end
Clear all messages across all topics.
@param [String] name The topic to clear.
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 39 def clear_all @queues&.values&.each { |e| e.clear } end
Publish a message to a topic.
@param [String] topic The name of the topic @param [Hash, String] payload The message content. @param [Hash] attrs The message attributes.
@return [Cloudenvoy::Message] The created message.
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 52 def publish(topic, payload, metadata = {}) msg = Message.new( id: SecureRandom.uuid, payload: payload, metadata: metadata, topic: topic ) queue(topic).push(msg) msg end
Return the message queue for a specific topic.
@param [String] name The topic to retrieve.
@return [Array] The list of messages for the provided topic
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 18 def queue(topic) @queues ||= {} @queues[topic.to_s] ||= [] end
Create or update a subscription for a specific topic.
@param [String] topic The name of the topic @param [String] name The name of the subscription @param [Hash] opts The subscription configuration options
@return [Cloudenvoy::Subscription] The upserted subscription.
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 73 def upsert_subscription(_topic, name, _opts) Subscription.new(name: name) end
Create or update a topic.
@param [String] topic The topic name.
@return [Cloudenvoy::Topic] The upserted topic.
# File lib/cloudenvoy/backend/memory_pub_sub.rb, line 84 def upsert_topic(topic) Topic.new(name: topic) end