Search code examples
phprabbitmqamqp

How to send an array using AMQPMessage - RabbitMQ


I'm trying to send an array using RabbitMQ, but the body of the message doesn't come on the receiver. If i a send a regular string works fine.

    $channel->queue_declare('hello', false, false, false, false);
    $array = array();
    array_push($array, "test");
    array_push($array, "test2");
    $msg = new AMQPMessage($array);
    $channel->basic_publish($msg, '', 'hello');

Solution

  • Just encode the array to JSON before send and after receiving the same decode the same JSON to array.