Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Message always publish to localhost. Reuse base 'channel' method to publ... #14

Merged
merged 1 commit into from

4 participants

@pavel-drobushevich

...ish and subscribe on one instance (via change connection host to not localhost).

@pavel-drobushevich pavel-drobushevich Message always publish to localhost. Reuse base 'channel' method to p…
…ublish and subscribe on one instance (via change connection host to not localhost).
961b21b
@majek

I'm not a ruby person. What's the difference?

@pavel-drobushevich

Old code call following method:
AMQP::Exchange.default
Source code for this method:
https://github.com/ruby-amqp/amqp/blob/master/lib/amqp/exchange.rb (line 149 and below)
This method has one argument - channel to connect, If this argument is not provided exchange creates default channel which connects to localhost. It is not expected, because FibonacciRpcClient has own channel and in my case it was configured to remote RabbitMQ installation, but as result message try to send to default localhost channel (I don't have local instance).
There are two possible:
1. Use exist channel to create exchange
self.channel.default_exchange
2. Send exist channel to this method
AMQP::Exchange.default(self.channel)

@michaelklishin

The idea is to not allocate a new channel implicitly. In practical terms, it makes no difference for tutorials but may lead to people doing this unknowingly in real world code, over and over.

@majek majek merged commit 248e69f into from
@dumbbell dumbbell added this to the n/a milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 18, 2012
  1. @pavel-drobushevich

    Message always publish to localhost. Reuse base 'channel' method to p…

    pavel-drobushevich authored
    …ublish and subscribe on one instance (via change connection host to not localhost).
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  ruby/rpc_client.rb
View
2  ruby/rpc_client.rb
@@ -33,7 +33,7 @@ def call(n, &block)
corr_id = rand(10_000_000).to_s
self.requests[corr_id] = nil
self.callback_queue.append_callback(:declare) do
- AMQP::Exchange.default.publish(n.to_s, :routing_key => "rpc_queue", :reply_to => self.callback_queue.name, :correlation_id => corr_id)
+ self.channel.default_exchange.publish(n.to_s, :routing_key => "rpc_queue", :reply_to => self.callback_queue.name, :correlation_id => corr_id)
EM.add_periodic_timer(0.1) do
# p self.requests
Something went wrong with that request. Please try again.