使用 AMQP 从 PHP 连接到 Apache ActiveMQ 时出现问题

Problem connection from PHP to Apache ActiveMQ using AMQP

我尝试在网上上下搜索 - 他们要么将我指向 RabbitMQ,这是不可能的,因为客户特别要求 ActiveMQ / Amazon MQ,这基本上是亚马逊云中的 ActiveMQ。其他结果建议使用不同的协议 (STOMP) - 我不能这样做,因为客户再次只允许通过 AMQP

访问

所以我不知所措..你能帮我开始吗?我尝试使用 PHPamqplib,但在建立连接期间访问已经 运行 的 activeMQ 代理时出现错误“....AbstractConnection.php:571 中的无效帧类型 65”。

<?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();
}
...

当我构建我的测试实例 class 以发送消息时,在构造函数的执行过程中已经发生错误。在你问之前,我尝试了库提供的不同 AMQP 连接类型——错误总是一样的。老实说,当它在 C# 中使用 amqpnetlite 库工作时,我有点不知所措缺少什么以及这个错误源于何处。任何帮助将不胜感激!

根据 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. According to this thread 没有计划在 php-amqplib 中支持 AMQP 1.0。

amqpnetlite client supports AMQP 1.0 这就是它与 ActiveMQ 一起工作的原因。