Class: EventQ::Amazon::EventQClient
- Inherits:
-
Object
- Object
- EventQ::Amazon::EventQClient
- Defined in:
- lib/eventq_aws/aws_eventq_client.rb
Overview
Implements a general interface to raise an event EventQ::RabbitMq::EventQClient is the sister-class which does the same for RabbitMq
Instance Method Summary collapse
-
#initialize(options) ⇒ EventQClient
constructor
A new instance of EventQClient.
- #new_message ⇒ Object
- #publish(topic:, event:, context: {}) ⇒ Object
- #raise_event(event_type, event, context = {}) ⇒ Object
- #raise_event_in_queue(event_type, event, queue, delay, context = {}) ⇒ Object
- #register_event(event_type) ⇒ Object
- #registered?(event_type) ⇒ Boolean
Constructor Details
#initialize(options) ⇒ EventQClient
Returns a new instance of EventQClient.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 7 def initialize() if [:client] == nil raise ':client (QueueClient) must be specified.'.freeze end @client = [:client] @serialization_manager = EventQ::SerializationProviders::Manager.new @signature_manager = EventQ::SignatureProviders::Manager.new #this array is used to record known event types @known_event_types = [] end |
Instance Method Details
#new_message ⇒ Object
78 79 80 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 78 def EventQ::QueueMessage.new end |
#publish(topic:, event:, context: {}) ⇒ Object
37 38 39 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 37 def publish(topic:, event:, context: {}) raise_event(topic, event, context) end |
#raise_event(event_type, event, context = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 41 def raise_event(event_type, event, context = {}) register_event(event_type) (event_type, event, context) do || response = @client.sns.publish( topic_arn: topic_arn(event_type), message: , subject: event_type ) EventQ.logger.debug do "[#{self.class} #raise_event] - Published to SNS with topic_arn: #{topic_arn(event_type)} | event_type: #{event_type} | Message: #{}" end response end end |
#raise_event_in_queue(event_type, event, queue, delay, context = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 60 def raise_event_in_queue(event_type, event, queue, delay, context = {}) queue_url = @client.get_queue_url(queue) (event_type, event, context) do || response = @client.sqs.( queue_url: queue_url, message_body: (), delay_seconds: delay ) EventQ.logger.debug do "[#{self.class} #raise_event_in_queue] - Raised event to SQS queue: #{queue_url} | event_type: #{event_type} | Message: #{}" end response end end |
#register_event(event_type) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 27 def register_event(event_type) if registered?(event_type) return true end @client.create_topic_arn(event_type) @known_event_types << event_type true end |
#registered?(event_type) ⇒ Boolean
23 24 25 |
# File 'lib/eventq_aws/aws_eventq_client.rb', line 23 def registered?(event_type) @known_event_types.include?(event_type) end |