Class: OpenWFE::Extras::SqsParticipant
- Inherits:
-
Object
- Object
- OpenWFE::Extras::SqsParticipant
- Includes:
- LocalParticipant
- Defined in:
- lib/openwfe/extras/participants/sqsparticipants.rb
Overview
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
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#queue_service ⇒ Object
readonly
Returns the value of attribute queue_service.
Instance Method Summary collapse
-
#consume(workitem) ⇒ Object
The method called by the engine when it has a workitem for this participant.
-
#initialize(queue_name, host_name = nil) ⇒ SqsParticipant
constructor
Builds an SqsParticipant instance pointing to a given queue.
Constructor Details
#initialize(queue_name, host_name = nil) ⇒ SqsParticipant
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’
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/openwfe/extras/participants/sqsparticipants.rb', line 77 def initialize (queue_name, host_name=nil) @queue_name = queue_name @queue_service = SQS::QueueService.new(host_name) @queue_service.create_queue(@queue_name) # make sure the queue exists @queue = @queue_service.get_queue(@queue_name) end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
69 70 71 |
# File 'lib/openwfe/extras/participants/sqsparticipants.rb', line 69 def queue @queue end |
#queue_service ⇒ Object (readonly)
Returns the value of attribute queue_service.
69 70 71 |
# File 'lib/openwfe/extras/participants/sqsparticipants.rb', line 69 def queue_service @queue_service end |
Instance Method Details
#consume(workitem) ⇒ Object
The method called by the engine when it has a workitem for this participant.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/openwfe/extras/participants/sqsparticipants.rb', line 93 def consume (workitem) msg = encode_workitem(workitem) msg_id = @queue_service.(@queue, msg) ldebug do "consume() msg sent to queue #{@queue.path} id is #{msg_id}" end end |