Sender-selected distribution appears to not work

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Sender-selected distribution appears to not work

Laing, Michael P.
I would like to use this feature as documented at http://www.rabbitmq.com/blog/2011/03/ and http://www.rabbitmq.com/extensions.html

I tested both manually using the management console and with a coffeescript program but cannot make it work.

Of course it is possible – even probable – that I have an error in understanding… :)

My application is one where I would like to publish each message using multiple routing keys.

In general each subscriber will bind with one key.

Here is a test that fails both on my mac using RabbitMQ 2.7.1 / Erlang R15B and a linux box using RabbitMQ 2.7.1 / Erlang R14B:

# test.coffee
amqp = require 'amqp'

t1_message = (message, headers, properties) ->
  console.log ""+
    "\nSuccess: t1: message: #{JSON.stringify message}"+
    "\nheaders: #{JSON.stringify headers}"+
    "\nproperties: #{JSON.stringify properties, undefined, 4}"
    
  process.exit 0
  
t0_message = (message, headers, properties) ->
  console.log ""+
    "\nBroadcast: t0: message: #{JSON.stringify message}"+
    "\nheaders: #{JSON.stringify headers}"+
    "\nproperties: #{JSON.stringify properties, undefined, 4}"
  
bailout = -> 
  console.log "\nFailure"
  process.exit 1

amqp_connection = amqp.createConnection()

amqp_connection.on 'ready', () -> 
  properties = type:'topic', durable: true

  amqp_connection.exchange "test", properties, (exchange) ->
    properties = durable:true, autoDelete:false

    amqp_connection.queue "t1", properties, (queue) ->
      queue.bind exchange, "foo"
      
      queue.subscribe (message, headers, properties) -> 
        t1_message message, headers, properties

      amqp_connection.queue "t0", properties, (queue) ->
        queue.bind exchange, "*"
        
        queue.subscribe (message, headers, properties) -> 
          t0_message message, headers, properties
        
        cc_header = cc:["foo","bar"]
        properties = contentType:"application/json", headers:cc_header
        message = test:"message content"
        exchange.publish "whatever", message, properties
        setTimeout bailout, 1000

Here's the output – if it had succeeded, both queues would have received the message:

Broadcast: t0: message: {"test":"message content"}
headers: {"cc":{"0":"foo","1":"bar"}}
properties: {
"contentType": "application/json",
"headers": {
        "cc": {
"0": "foo",
"1": "bar"
}
},
"queue": "t0",
"deliveryTag": 1,
"redelivered": false,
"exchange": "test",
"routingKey": "whatever",
"consumerTag": "node-amqp-38169-0.10587440640665591"
}

Failure

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Matthias Radestock-3
On 21/04/12 13:27, Laing, Michael P. wrote:
> I would like to use this feature as documented at
> http://www.rabbitmq.com/blog/2011/03/ and
> http://www.rabbitmq.com/extensions.html
>
> I tested both manually using the management console and with a
> coffeescript program but cannot make it work.
>
> Of course it is possible – even probable – that I have an error in
> understanding… :)

s/cc/CC

See also the example at
http://hg.rabbitmq.com/rabbitmq-java-client/file/default/test/src/com/rabbitmq/client/test/functional/CcRoutes.java 
for clues.

Matthias.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Laing, Michael P.
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.

ml

On 4/21/12 8:53 AM, "Matthias Radestock" <[hidden email]> wrote:

>On 21/04/12 13:27, Laing, Michael P. wrote:
>> I would like to use this feature as documented at
>> http://www.rabbitmq.com/blog/2011/03/ and
>> http://www.rabbitmq.com/extensions.html
>>
>> I tested both manually using the management console and with a
>> coffeescript program but cannot make it work.
>>
>> Of course it is possible ­ even probable ­ that I have an error in
>> understandingŠ :)
>
>s/cc/CC
>
>See also the example at
>http://hg.rabbitmq.com/rabbitmq-java-client/file/default/test/src/com/rabb
>itmq/client/test/functional/CcRoutes.java
>for clues.
>
>Matthias.

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Matthias Radestock-3
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.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Laing, Michael P.
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" <[hidden email]> 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.

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Laing, Michael P.
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." <[hidden email]> 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" <[hidden email]> 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.
>

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

Matthias Radestock-3
On 22/04/12 00:45, Laing, Michael P. wrote:
> So, just to wrap this up, I switched to ruby, and sender-selected
> distribution worked as expected.

Glad you got it working in the end. I have filed a bug to improve our
documentation in this area.

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

I would hope that is easy to fix. Perhaps you could try producing a patch.

Matthias.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sender-selected distribution appears to not work

mufaddal
This post has NOT been accepted by the mailing list yet.
In case someone wondering how to make it work via RabbmitMQ UI interface ... it worked by selecting the type 'List' instead of 'String' from the drop-down for the header attribute (CC). I am using 3.4.1 version.
Loading...