def make_target(agent, type, collective, reply_to=nil, node=nil)
raise("Unknown target type #{type}") unless [:directed, :broadcast, :reply, :request, :direct_request].include?(type)
raise("Unknown collective '#{collective}' known collectives are '#{@config.collectives.join ', '}'") unless @config.collectives.include?(collective)
target = {:name => "", :headers => {}, :id => nil}
if reply_to
reply_path = reply_to
elsif get_bool_option("rabbitmq.use_reply_exchange", false)
reply_path = "/exchange/mcollective_reply/%s_%s_%s" % [ @config.identity, $$, Client.request_sequence ]
else
reply_path = "/temp-queue/mcollective_reply_%s" % agent
end
case type
when :reply
target[:name] = reply_path
target[:id] = "mcollective_%s_replies" % agent
when :broadcast, :request
target[:name] = "/exchange/%s_broadcast/%s" % [collective, agent]
if reply_to
target[:headers]["reply-to"] = reply_to
else
target[:headers]["reply-to"] = reply_path
end
target[:id] = "%s_broadcast_%s" % [collective, agent]
when :direct_request
raise "Directed requests need to have a node identity" unless node
target[:name] = "/exchange/%s_directed/%s" % [ collective, node]
target[:headers]["reply-to"] = reply_path
when :directed
target[:name] = "/exchange/%s_directed/%s" % [ collective, @config.identity ]
target[:id] = "%s_%s_directed_to_identity" % [ collective, @config.identity ]
end
target
end