require 'puppet/util/queue'
require 'stomp'
# Implements the Ruby Stomp client as a queue type within the Puppet::Indirector::Queue::Client
# registry, for use with the :queue indirection terminus type.
#
# Looks to Puppet[:queue_source] for the sole argument to the underlying Stomp::Client constructor;
# consequently, for this client to work, Puppet[:queue_source] must use the Stomp::Client URL-like
# syntax for identifying the Stomp message broker: login:pass@host.port
class Puppet::Util::Queue::Stomp
attr_accessor :stomp_client
def initialize
self.stomp_client = Stomp::Client.new( Puppet[:queue_source] )
end
def send_message(target, msg)
stomp_client.send(stompify_target(target), msg)
end
def subscribe(target)
stomp_client.subscribe(stompify_target(target)) {|stomp_message| yield(stomp_message.body)}
end
def stompify_target(target)
'/queue/' + target.to_s
end
Puppet::Util::Queue.register_queue_type(self, :stomp)
end