I’m pleased to announce yesterday’s release of SPQR 0.3.0, which is available as source, on github, or as a RubyGem. (SPQR is a library to make it painless to publish Ruby objects over the Qpid Management Framework; more details are available elsewhere on this site.)
There are several new features and enhancements in this release, including the ability to access the current Qpid user and context from within managed methods. The most exciting new functionality, though, is support for QMF events. In order to use QMF events, you’ll need a fairly recent version of the Qpid and QMF libraries from their source repository (later than revision 929717 for nearly-complete support; revision 942861 fixes a minor bug that won’t affect most users). Once you have those installed, though, SPQR makes it characteristically easy to make QMF events; see the example below for details:
#!/usr/bin/env ruby
# This is a simple logging service that operates over QMF. It is very similar
# to logservice.rb, except it makes QMF events for log events instead of
# database records. LogEventService has the same API as LogService; LogEvent
# is a SPQR event class. See the comments for details on how to use QMF events.
require 'spqr/spqr'
require 'spqr/app'
class LogEventService
include SPQR::Manageable
[:debug, :warn, :info, :error].each do |name|
do |msg|
define_method name # Construct a new event by passing arguments to .new in the order that they were declared
= LogEvent.new(Time.now.utc.to_i * 1000000000, "#{name.to_s.upcase}", msg.dup)
ev
# You can also set arguments of an event object individually, like this:
# ev = LogEvent.new
# ev.l_when = Time.now
# ev.severity = name.to_s.upcase
# ev.msg = msg.dup
# Once all of the arguments are set, raise the event:
.bang!
evend
do |args|
expose name .declare :msg, :lstr, :in
argsend
end
def self.find_all
@singleton ||= LogEventService.new
[@singleton]
end
def self.find_by_id(i)
@singleton ||= LogEventService.new
end
:examples
qmf_package_name :LogEventService
qmf_class_name end
class LogEvent
# To declare an event class, include SPQR::Raiseable
include ::SPQR::Raiseable
# Declare arguments with their name, type, and (optional) description
:l_when, :absTime, "When the event happened"
arg :severity, :sstr, "Event severity: DEBUG, WARN, INFO, or ERROR"
arg :msg, :lstr, "Log message"
arg
# Declare metadata as appropriate
:examples
qmf_package_name :LogEvent
qmf_class_name end
= SPQR::App.new(:loglevel => :debug)
app
# Event classes must be registered just like object classes
.register LogEventService, LogEvent
app
.main app
As usual, I welcome your feedback.