[rabbitmq-discuss] php talking to ruby

Robin Wood robin at digininja.org
Wed Jan 19 10:24:14 GMT 2011


I think I've got a little bit further from where I was when I
originally posted so here are the examples I'm working on now.

This is the Ruby consumer that I've got. It has come directly from the
Gem examples, it just listens for messages:

$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'
require 'pp'

EM.run do

  # connect to the amqp server
  connection = AMQP.connect(:host => 'localhost', :logging => false)

  # open a channel on the AMQP connection
  channel = MQ.new(connection)

  # declare a queue on the channel
  queue = MQ::Queue.new(channel, 'queue1')

  # create a fanout exchange
  exchange = MQ::Exchange.new(channel, :direct, 'direct1')

  # bind the queue to the exchange
  queue.bind(exchange)

  # subscribe to messages in the queue
  queue.subscribe do |headers, msg|
    pp [:got, headers, msg]
    connection.close{ EM.stop_event_loop }
  end

end

If I understand things right I've got it setup to listen for direct
messages in queue1 on an exchange called direct1.

Seeing as you are offering help with PECL I've got the example from
the php site

<?php

// Create a connection
$cnn = new AMQPConnection();
$cnn->connect();

// Declare a new exchange
$ex = new AMQPExchange($cnn);
$ex->declare('direct1', AMQP_EX_TYPE_DIRECT);

// Create a new queue
$q = new AMQPQueue($cnn);
$q->declare('queue1');

// Bind it on the exchange to routing.key
$ex->bind('queue1', 'routing.key');

// Publish a message to the exchange with a routing key
$ex->publish('message', 'routing.key');

// Read from the queue
$msg = $q->consume();

?>

This should be trying to publish a message to queue1 on exchange direct1.

When I run the php I get:

PHP Fatal error:  Uncaught exception 'AMQPQueueException' with message
'Server channel error: 406, message: PRECONDITION_FAILED - parameters
for queue 'queue1' in vhost '/' not equivalent' in
/home/robin/sched/a.php:13
Stack trace:
#0 /home/robin/sched/a.php(13): AMQPQueue->declare('queue1')
#1 {main}
  thrown in /home/robin/sched/a.php on line 13

Don't know if this output will help or not:

scheduler:/etc/php5/cli/conf.d# rabbitmqctl list_queues
Listing queues ...
queue1  0
...done.

scheduler:/etc/php5/cli/conf.d# rabbitmqctl list_vhosts
Listing vhosts ...
/
...done.

scheduler:/etc/php5/cli/conf.d# rabbitmqctl list_exchanges
Listing exchanges ...
amq.rabbitmq.log        topic
amq.match       headers
direct1 direct
amq.headers     headers
amq.topic       topic
amq.direct      direct
amq.fanout      fanout
        direct
...done.


Just in case I'm going about this the wrong way, the aim of all this
is to simply get a php web app to be able to send messages off to a
Ruby scheduler application which then in its own time processes the
request then sends the resulting data back. At the moment it is one to
one communication, that is why I went for direct rather than fanout.

I guess once I get communication going in one direction I hope the
reverse should be fairly simply.

I'd normally prefer to do a lot more reading around a new technology
before shouting for help but I've been given a short deadline and the
communication level is the lowest priority as we could potentially
just do this by calling shell scripts but I'd rather do it the proper
way.

Robin



2011/1/19 Pieter de Zwart <pdezwart at rubiconproject.com>:
> Robin,
>
> There is no reason why you cant do this. We are currently actively using the
> PHP PECL extension to read messages published by both a Perl and Python
> client. I know I hate it when people ask this of me, but could you cobble
> together some very basic sample code and let us know what client versions
> you are using? If it's the PHP client's fault, I will be more than happy to
> fix it.
>
> me
>
>
> On 1/18/11 3:45 PM, "Robin Wood" <robin at digininja.org> wrote:
>
>> 2011/1/18 Alexandre Kalendarev <akalend at mail.ru>:
>> Robin,
>>
>> You must to use
>> the universal  data  format : JSON or XML, or other conventional
>> dataformat.
>>
>
> I'm completely new to RabbitMQ, any pointers as to where to
>> look for
> this? Do you know if both the libraries I've chosen will do
>> this?
>
> Robin
>
>> Alexandre
>>
>>
>> Tue, 18 Jan 2011 20:13:10 +0000 письмо от
>> Robin Wood <robin at digininja.org>:
>>
>>> Hi
>>> I'm trying to get Ruby, using the
>> AMQP gem to talk to PHP using the
>>> php-amqp library. Both on their own work
>> and talk between their own
>>> consumer/publisher but I can't get them to talk
>> cross language.
>>>
>>> Before I post my randomly hacked together code does
>> anyone have good
>>> sample code that shows the two languages talking to each
>> other?
>>>
>>> I'm new to MQ stuff but roughly what I'm seeing is the channel
>> and
>>> queues are being created OK and messages are being sent but when I
>>>
>> watch them in Wireshark I see the PHP one has a content type of
>>> plain/text
>> but the Ruby message has application/octet.
>>>
>>> Any tips?
>>>
>>> Robin
>>>
>> _______________________________________________
>>> rabbitmq-discuss mailing
>> list
>>> rabbitmq-discuss at lists.rabbitmq.com
>>>
>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>
>>
>> _______________________________________________
>> rabbitmq-discuss mailing
>> list
>> rabbitmq-discuss at lists.rabbitmq.com
>>
>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>
> _______
>> ________________________________________
> rabbitmq-discuss mailing
>> list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/ma
>> ilman/listinfo/rabbitmq-discuss
>
>
> --
> the rubicon project
>
> PIETER DE ZWART | LEAD, INTERFACES TEAM
> *** P 310 207 0272 | x224
> *** C 408 666 4443
> *** F 323 466 7119
>
>
> 1925 S. BUNDY DRIVE
> LOS ANGELES, CALIFORNIA 90025
>
> WWW.RUBICONPROJECT.COM <http://www.rubiconproject.com/>
>
>
> "MOST INNOVATIVE COMPANY" - AMERICAN BUSINESS AWARDS '10
>  REVV IS OPTIMIZING 1.4 MILLION ADS PER MINUTE
>
>
>


More information about the rabbitmq-discuss mailing list