phpactivemq-classicamqpphp-amqplib

Problem connecting from PHP to Apache ActiveMQ using AMQP


I tried searching the web up and down - and either they point me towards RabbitMQ which is out of the question because the customer specifically asked for ActiveMQ / Amazon MQ which is basically ActiveMQ in the Amazon cloud. Other results suggest using a different protocol (STOMP) - which I cant do because again the customer allows only the access via AMQP

So I'm at a loss .. can you help me get going ? I tried with PHPamqplib but I get errors accessing the already running activeMQ broker "Invalid frame type 65 in ....AbstractConnection.php:571" during connection build up.

    <?php
    namespace Test;
    require_once __DIR__.'/vendor/autoload.php';
    use PhpAmqpLib\Connection\AMQPSocketConnection;
    use PhpAmqpLib\Message\AMQPMessage;

    class Test {
       private $host='192.168.3.66';
       private $port=5672;
       private $user='guest';
       private $password='guest';
       protected $connection;
       protected $channel;

    public function __construct() {
       $this->connection=new AMQPSocketConnection($this->host, $this->port, $this->user,$this->password);
       $this->channel=$this->connection->channel();
    }
    ...

The error occurs already here during execution of the constructor, when I build an instance of my Test class to send messages. Before you ask, I tried with different AMQP connection types offered by the library - the error is always the same. Honestly as it worked in C# using the amqpnetlite library I'm a bit at a loss what is missing and where this error stems from. Any help would be greatly appreciated!


Solution

  • According to the README.md php-amqplib supports AMQP 0.9.1. However, ActiveMQ supports AMQP 1.0. Unfortunately the two protocols are not compatible. You'll need to find a PHP AMQP client which supports 1.0 if you want to communicate with ActiveMQ or Amazon MQ via AMQP. According to this thread there are no plans to support AMQP 1.0 in php-amqplib.

    The amqpnetlite client supports AMQP 1.0 which is why it works with ActiveMQ.