O'Reilly logo

Learning MCollective by Jo Rhett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. Collecting Responses

One of the features which makes MCollective truly unique is the ability to send requests from one client, and to process the responses with a different client or Listener.

Request responses return via a custom queue to a Listener
Figure 15-1. A separate Listener to process results from requests

Create a Listener

The first thing we’ll do here is to create a listener. What I’ll introduce to you here is a working listener from which you can debug any problem. You can also copy it and add new functionality. I put my listeners in the $libdir directory just like every other plugin, but that’s not necessary nor standard.

$ cat /usr/libexec/mcollective/mcollective/listener/debugger.rb
# Parse options, load config, and start an MCollective client.
require 'mcollective'
optparser = MCollective::Optionparser.new
options = optparser.parse
config = MCollective::Config.instance
config.loadconfig(options[:config])
MCollective::PluginManager["security_plugin"].initiated_by = :client
connector = MCollective::PluginManager['connector_plugin']
connector.connect

# Get pretty-print and the Log object
require 'pp'
Log = MCollective::Log

# Get a reply queue name from anywhere, hardcoded here
replyqueue = 'debugger'
queuename = '/queue/mcollective.reply.' + replyqueue

# Here is the queue we want to listen to
connector.connection.subscribe( queuename, {}, "$$".to_i )

# consume all the things...
loop do
  # Get an mcollective Message object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required