spiral-modules / jobs

RoadRunner: Background PHP workers, Queue brokers
MIT License
60 stars 11 forks source link

[BUG] Error "missing header rr-attempt" although this header exist in AMQP message #49

Closed mqwerty closed 3 years ago

mqwerty commented 4 years ago

RoadRunner, PHP Application Server Version: 2.4.18, 2020-05-23T19:45:45+0300

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;

chdir(__DIR__);
require_once __DIR__ . '/vendor/autoload.php';

$id = bin2hex(random_bytes(16));
$message = new AMQPMessage(
    'test',
    [
        'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
        'content_type' => 'application/octet-stream',
        'application_headers' => new AMQPTable(
            [
                'rr-id' => $id,
                'rr-attempt' => 0,
                'rr-delay' => 0,
                'rr-job' => 'local.test',
                'rr-maxAttempts' => 0,
                'rr-retryDelay' => 0,
                'rr-timeout' => 0,
            ]
        ),
    ]
);

$amqp = new AMQPStreamConnection('rabbitmq', '5672', 'guest', 'guest');
$amqp->channel()->basic_publish($message, 'local.test', 'local.test');

Screenshot from RabbitMQ admin panel:

20200610_133723

The same error when I send a message from the RabbitMQ admin panel.

mqwerty commented 4 years ago

RoadRunner config:

jobs:
  workers.command: "php /app/j.php"
  amqp.addr: amqp://guest:guest@rabbitmq:5672/
  pipelines:
    local:
      broker: "amqp"
      queue: "local.test"
      exchange: "local.test"
  consume: ["local"]
  dispatch:
    app-job-*.pipeline: "local"

RabbitMQ config:

{
  "queues": [
    {
      "name": "local.test",
      "vhost": "/",
      "durable": true,
      "auto_delete": false,
      "arguments": {}
    }
  ],
  "bindings": [
    {
      "source": "local.test",
      "vhost": "/",
      "destination": "local.test",
      "destination_type": "queue",
      "routing_key": "local.test",
      "arguments": {}
    }
  ],
  "exchanges": [
    {
      "name": "local.test",
      "vhost": "/",
      "type": "direct",
      "durable": true,
      "auto_delete": false,
      "internal": false,
      "arguments": {}
    }
  ]
}
mqwerty commented 4 years ago

But when i send message through RPC - it works and no error, although the headings are the same.

use Spiral\Goridge\RPC;
use Spiral\Goridge\SocketRelay;

chdir(__DIR__);
require_once __DIR__ . '/vendor/autoload.php';

$rpc = new RPC(new SocketRelay('127.0.0.1', 6001));

$rpc->call('jobs.Push', [
    'job'     => 'local.test',
    'payload' => 'test',
    'options' => ['pipeline' => 'local']
]);

20200610_134809

wolfy-j commented 4 years ago

Weird. https://dev.to/sergey_telpuk/send-job-from-node-app-to-php-app-via-queue-8do Sending messages from other clients is def possible and tested.

wolfy-j commented 4 years ago

We have to check what headers received by the AMQP broker. This is weird.

mqwerty commented 4 years ago

With php-amqp works fine.

$id = bin2hex(random_bytes(16));
$headers = ['headers' => [
    'rr-id' => $id,
    'rr-attempt' => 0,
    'rr-job' => 'local.test',
]];

$connect = (new AMQPConnection(
    [
        'host' => 'rabbitmq',
        'port' => 5672,
        'login' => 'guest',
        'password' => 'guest',
    ]
));
$connect->pconnect();

$exchange = new AMQPExchange(new AMQPChannel($connect));
$exchange->publish('test', 'local.test', AMQP_MANDATORY, $headers);

The problem is only with php-amqplib client. But in RabbitMQ admin panel i see 'rr-attempt' header. It is really strange that RoadRunner does not see it.

wolfy-j commented 4 years ago

Maybe it uses some legacy format of headers...

rustatian commented 3 years ago

Feel free to re-open this issue for the RR2 and new jobs plugin (will be soon in 2.4.0-beta1) if you get the same behavior. This repo now is deprecated for the golang part.