diff options
author | Ethan Rowe <ethan@endpoint.com> | 2009-04-13 07:33:11 -0400 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-04-22 14:39:37 +1000 |
commit | 7947f100a9d9d60d1038e220aa41d44cf59d5af0 (patch) | |
tree | f9c71a5783ad85d17b7e702b1ff706dc34a7dff6 /lib/puppet/util/queue/stomp.rb | |
parent | 80dc83715190335ec0aac142e383d60ca28ea3b3 (diff) | |
download | puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.gz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.xz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.zip |
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.
Diffstat (limited to 'lib/puppet/util/queue/stomp.rb')
-rw-r--r-- | lib/puppet/util/queue/stomp.rb | 30 |
1 files changed, 30 insertions, 0 deletions
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 <tt>:queue</tt> indirection terminus type. +# +# Looks to <tt>Puppet[:queue_source]</tt> for the sole argument to the underlying Stomp::Client constructor; +# consequently, for this client to work, <tt>Puppet[:queue_source]</tt> must use the Stomp::Client URL-like +# syntax for identifying the Stomp message broker: <em>login:pass@host.port</em> +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 |