Class: EventQ::Amazon::EventQClient

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_aws/aws_eventq_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ EventQClient

Returns a new instance of EventQClient.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/eventq_aws/aws_eventq_client.rb', line 5

def initialize(options)

  if options[:client] == nil
    raise ':client (QueueClient) must be specified.'.freeze
  end

  @client = options[:client]

  @serialization_manager = EventQ::SerializationProviders::Manager.new

end

Instance Method Details

#new_messageObject



43
44
45
# File 'lib/eventq_aws/aws_eventq_client.rb', line 43

def new_message
  EventQ::QueueMessage.new
end

#raise_event(event_type, event) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/eventq_aws/aws_eventq_client.rb', line 17

def raise_event(event_type, event)

  _event_type = EventQ.create_event_type(event_type)

  topic_arn = @client.get_topic_arn(_event_type)

  qm = new_message
  qm.content = event
  qm.type = _event_type

  serialization_provider = @serialization_manager.get_provider(EventQ::Configuration.serialization_provider)

  message = serialization_provider.serialize(qm)

  response = @client.sns.publish({
                                     topic_arn: topic_arn,
                                     message: message,
                                     subject: event_type
                                 })

  EventQ.log(:debug, "[#{self.class}] - Raised event. Message: #{message} | Type: #{event_type}.")

  return response.message_id

end