Created
June 11, 2014 20:09
-
-
Save tedkulp/9eb3dd8f1379f2f5ef91 to your computer and use it in GitHub Desktop.
Ruby version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'rubygems' | |
require 'amqp' | |
require 'json' | |
EventMachine.run do | |
connection = AMQP.connect(:host => '192.168.100.10', :user => 'admin', :password => 'changeme') | |
channel = AMQP::Channel.new(connection) | |
exchange = channel.topic("rpc_exchange") | |
queue = channel.queue("echo.*", :auto_delete => true).bind(exchange, :routing_key => "echo.*") | |
queue.subscribe do |headers, payload| | |
json_payload = JSON.parse(payload) | |
if json_payload['message'] | |
reply = { | |
:echo => true, | |
:message => json_payload['message'] | |
} | |
puts reply | |
exchange.publish JSON.generate(reply), :routing_key => headers.reply_to, :correlation_id => headers.correlation_id, :content_type => headers.content_type | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment