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 =
options = optparser.parse
config = MCollective::Config.instance
MCollective::PluginManager["security_plugin"].initiated_by = :client
connector = MCollective::PluginManager['connector_plugin']

# 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 ...

Get Learning MCollective now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.