[rabbitmq-discuss] Sender-selected distribution appears to not work

Laing, Michael P. Michael.Laing at nytimes.com
Sun Apr 22 00:45:47 BST 2012


The client library for nodejs, 'amqp', does not have support for the amqp
array data type in headers; I reported it.

So, just to wrap this up, I switched to ruby, and sender-selected
distribution worked as expected.

I will be implementing my app in ruby or python I guess - at least the
publisher portion.

Here's a ruby equivalent to the coffeescript I posted earlier; the message
is delivered to both queues:

#!/usr/bin/env ruby
# encoding: utf-8

require "rubygems"
require 'amqp'
require 'json'
require 'time'

EventMachine.run do
  AMQP.connect() do |connection|
    AMQP::Channel.new(connection) do |channel, open_ok|
      channel.on_error{|ch, err| puts "channel error: #{err.reply_text}"}
      exchange = channel.topic "test", :durable => true, :autoDelete =>
false
      t1_q = channel.queue "t1", :durable => true, :autoDelete => false
      

      t1_q.bind(exchange, :key => "foo").subscribe do |properties, message|
        puts(
          "\n#{Time.now.utc.iso8601(6)} got t1 (success)"+
          "\n  message: #{message}"+
          "\n  properties: #{properties.attributes.inspect}"
        )
      End
      

      t0_q = channel.queue "t0", :durable => true

      t0_q.bind(exchange, :key => "*").subscribe do |properties, message|
        puts(
          "\n#{Time.now.utc.iso8601(6)} got t0 (expected)"+
          "\n  message: #{message}"+
          "\n  properties: #{properties.attributes.inspect}"
        )
      End

      
      message = {:test => "message"}
      cc_header = ["foo","bar"] # note array

      
      exchange.publish(
        message.to_json(),
        :routing_key => "whatever",
        :headers => {:CC => cc_header},
        :content_type => "application/json"
      )
    end
  end
end




On 4/21/12 9:25 AM, "Laing, Michael P." <Michael.Laing at nytimes.com> wrote:

>If I quote the "CC" in the management console, I no longer get the 406
>failure.
>
>But my 'guessed at' format for array args in the console didn't work: I'll
>experiment a bit.
>
>And I'll dive into the client library for my test program.
>
>I can always switch from nodejs to ruby if necessary. The nodejs library
>is quite sketchy, unfortunately.
>
>Thanks!
>
>ml
>
>On 4/21/12 9:15 AM, "Matthias Radestock" <matthias at rabbitmq.com> wrote:
>
>>On 21/04/12 14:05, Laing, Michael P. wrote:
>>> Unfortunately, testing via the management console returns this:
>>>
>>> 406 PRECONDITION_FAILED - invalid message:
>>> {unacceptable_type_in_header,longstr,"CC"}
>>>
>>>
>>> (although it's not really clear how to enter an array in the field)
>>>
>>> Testing via my program returns something similar:
>>>
>>> Unhandled channel error: PRECONDITION_FAILED - invalid message:
>>> {unacceptable_type_in_header,table,"CC"}
>>>
>>>
>>> It seems to reject "CC" as a header.
>>
>>The header value needs to be an AMQP 'array'. Unfortunately I have no
>>idea how to enter that in the management UI or how to produce such a
>>header in the client library you are using.
>>
>>Matthias.
>



More information about the rabbitmq-discuss mailing list