When using the pooled configuration syntax you now automatically get detailed logging at info level for connection events on the Stomp connetion.
This is based on a feature in Stomp 1.1.9 where you can have a class that responds to some predictable method names to create call back based logging. The stomp plugin constains a class M::C::Stomp::EventLogger that has these methods and does the logging using the normal logging framework. Signed-off-by: R.I.Pienaar <[email protected]> --- Local-branch: feature/master/7960 plugins/mcollective/connector/stomp.rb | 35 ++++++++++++++++++++ .../connector/stomp/eventlogger_spec.rb | 32 ++++++++++++++++++ .../plugins/mcollective/connector/stomp_spec.rb | 3 ++ website/changelog.md | 1 + website/reference/plugins/connector_stomp.md | 3 ++ 5 files changed, 74 insertions(+), 0 deletions(-) create mode 100644 spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb diff --git a/plugins/mcollective/connector/stomp.rb b/plugins/mcollective/connector/stomp.rb index f19e8c2..365eee9 100644 --- a/plugins/mcollective/connector/stomp.rb +++ b/plugins/mcollective/connector/stomp.rb @@ -59,6 +59,38 @@ module MCollective # plugin.stomp.priority = 4 # class Stomp<Base + # Class for Stomp 1.9.2 callback based logging + class EventLogger + def on_connecting(params=nil) + Log.info("Connection attempt %d to %s" % [params[:cur_conattempts], stomp_url(params)]) + rescue + end + + def on_connected(params=nil) + Log.info("Conncted to #{stomp_url(params)}") + rescue + end + + def on_disconnect(params=nil) + Log.info("Disconnected from #{stomp_url(params)}") + rescue + end + + def on_connectfail(params=nil) + Log.info("Connction to #{stomp_url(params)} failed on attempt #{params[:cur_conattempts]}") + rescue + end + + def on_miscerr(params, errstr) + Log.debug("Unexpected error on connection #{stomp_url(params)}: #{errstr}") + rescue + end + + def stomp_url(params) + "stomp://%s@%s:%d" % [params[:cur_login], params[:cur_host], params[:cur_port]] + end + end + attr_reader :connection def initialize @@ -122,6 +154,9 @@ module MCollective connection[:backup] = get_bool_option("stomp.pool.backup", false) connection[:timeout] = get_option("stomp.pool.timeout", -1).to_i + stomp_logger = EventLogger.new + connection[:logger] = stomp_logger + @connection = connector.new(connection) end rescue Exception => e diff --git a/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb b/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb new file mode 100644 index 0000000..847f32b --- /dev/null +++ b/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../../../spec_helper' + +MCollective::PluginManager.clear + +require File.dirname(__FILE__) + '/../../../../../../plugins/mcollective/connector/stomp.rb' + +module MCollective + module Connector + class Stomp + describe EventLogger do + before do + end + + it "should have valid call back methods" do + plugin = EventLogger.new + + [:on_miscerr, :on_connecting, :on_connected, :on_disconnect, :on_connectfail].each do |meth| + plugin.respond_to?(meth).should == true + end + end + + describe "#stomp_url" do + it "should create valid stomp urls" do + EventLogger.new.stomp_url({:cur_login => "rspec", :cur_host => "localhost", :cur_port => 123}).should == "stomp://rspec@localhost:123" + end + end + end + end + end +end diff --git a/spec/unit/plugins/mcollective/connector/stomp_spec.rb b/spec/unit/plugins/mcollective/connector/stomp_spec.rb index 0e37f99..a1c0348 100644 --- a/spec/unit/plugins/mcollective/connector/stomp_spec.rb +++ b/spec/unit/plugins/mcollective/connector/stomp_spec.rb @@ -106,6 +106,8 @@ module MCollective @config.expects(:pluginconf).returns(pluginconf).at_least_once + Stomp::EventLogger.expects(:new).returns("logger") + connector = mock connector.expects(:new).with(:backup => true, :back_off_multiplier => 2, @@ -115,6 +117,7 @@ module MCollective :max_reconnect_attempts => 5, :initial_reconnect_delay => 0.02, :randomize => true, + :logger => "logger", :hosts => [{:passcode => 'password1', :host => 'host1', :port => 6163, diff --git a/website/changelog.md b/website/changelog.md index 08fb06c..2b4b876 100644 --- a/website/changelog.md +++ b/website/changelog.md @@ -11,6 +11,7 @@ title: Changelog |Date|Description|Ticket| |----|-----------|------| +|2011/06/21|Add support for Stomp Gem version 1.1.9 callback based logging|7960| |2011/06/21|On the server side log missing DDL files at debug and not warning level|7961| |2011/06/16|Add the ability for nodes to subscribe to per-node queues, off by default|7225| |2011/06/12|Remove assumptions about middleware structure from the core and move it to the connector plugins|7619| diff --git a/website/reference/plugins/connector_stomp.md b/website/reference/plugins/connector_stomp.md index ec54220..32cfc9b 100644 --- a/website/reference/plugins/connector_stomp.md +++ b/website/reference/plugins/connector_stomp.md @@ -33,6 +33,9 @@ If you are seeing issues with the Stomp gem logging protocol errors and resettin ### Failover Pools Newer versions of the Stomp gem supports failover between multiple Stomp servers, you need at least _1.1.6_ to use this. +If you are using version _1.1.9_ and newer of the Stomp Gem and this method of configuration you will also receive more detailed +logging about connections, failures and other significant events. + {% highlight ini %} connector = stomp plugin.stomp.pool.size = 2 -- 1.7.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
