| Class | OpenWFE::Extras::SqsParticipant |
| In: |
lib/openwfe/extras/participants/sqsparticipants.rb
|
| Parent: | Object |
This participant dispatches its workitem to an Amazon SQS queue.
If the queue doesn‘t exist, the participant will create it.
a small example :
# ...
engine.register_participant(:sqs0, SqsParticipant.new("workqueue0"))
# ...
For more details about SQS : aws.amazon.com
| queue | [R] | |
| queue_service | [R] |
Builds an SqsParticipant instance pointing to a given queue. (Refer to the SQS service on how to set up AWS key ids).
By default the host_name is ‘queue.amazonaws.com‘
# File lib/openwfe/extras/participants/sqsparticipants.rb, line 78
78: def initialize (queue_name, host_name=nil)
79:
80: @queue_name = queue_name
81:
82: @queue_service = Rufus::SQS::QueueService.new host_name
83:
84: @queue_service.create_queue @queue_name
85: # make sure the queue exists
86:
87: @queue = @queue_service.get_queue @queue_name
88: end
The method called by the engine when it has a workitem for this participant.
# File lib/openwfe/extras/participants/sqsparticipants.rb, line 94
94: def consume (workitem)
95:
96: msg = encode_workitem workitem
97:
98: msg_id = @queue_service.put_message @queue, msg
99:
100: ldebug do
101: "consume() msg sent to queue #{@queue.path} id is #{msg_id}"
102: end
103: end
Turns the workitem into a Hash, pass it through YAML and encode64 the result.
Override this method as needed.
Something of ‘text/plain’ flavour should be returned.
# File lib/openwfe/extras/participants/sqsparticipants.rb, line 115
115: def encode_workitem (wi)
116:
117: msg = wi.to_h
118: msg = YAML.dump(msg)
119: msg = Base64.encode64(msg)
120: msg
121: end