From 7947f100a9d9d60d1038e220aa41d44cf59d5af0 Mon Sep 17 00:00:00 2001 From: Ethan Rowe Date: Mon, 13 Apr 2009 07:33:11 -0400 Subject: Introduce queue client "plugin" namespace and interface, with a Stomp client implementation. Puppet::Util::Queue provides queue client mix-in behaviors that enable easy queue client management for consumer classes. Some relevant behaviors include: * standard Puppet instance loader behavior for loading queue client modules on-demand based on the client module specified by symbolic name * singleton registry of known queue client types (based on symbol-to-class mappings from the instance loading behavior) * simple interface for working with an actual queue client instance Puppet::Util::Queue::Stomp wraps the Stomp::Client class to provide an initial queue client option supporting the Stomp messaging protocol. This defines the interface for all Puppet queue client plugins going forward. --- lib/puppet/util/queue/stomp.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/puppet/util/queue/stomp.rb (limited to 'lib/puppet/util/queue') diff --git a/lib/puppet/util/queue/stomp.rb b/lib/puppet/util/queue/stomp.rb new file mode 100644 index 000000000..6f845c314 --- /dev/null +++ b/lib/puppet/util/queue/stomp.rb @@ -0,0 +1,30 @@ +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 -- cgit