Skip to content

Drivers ​

The four classes in src/Driver all implement DriverInterface. Pick one for the emitter and the same one for the dispatcher. They must agree on the queue name, the priority keys, and the schedule key, because those strings are the queue.

Comparison ​

Redis ext-redisPredisRabbitMQ lazyAmazon SQS
ClassRedisSetDriverPredisSetDriverLazyRabbitMqDriverAmazonSqsDriver
Priority✓set per priority✓set per priority✗throws NotSupportedException✗throws NotSupportedException
Delay✓sorted set✓sorted set✗published at once✗sent at once
Persistence~Redis RDB or AOF config~Redis RDB or AOF config✓durable queue✓stored by SQS
Ack✗removed before the handler✗removed before the handler✓ack after the handler✓deleted after the handler

Redis ext-redis

Class
RedisSetDriver
Priority
✓set per priority
Delay
✓sorted set
Persistence
~Redis RDB or AOF config
Ack
✗removed before the handler

Predis

Class
PredisSetDriver
Priority
✓set per priority
Delay
✓sorted set
Persistence
~Redis RDB or AOF config
Ack
✗removed before the handler

RabbitMQ lazy

Class
LazyRabbitMqDriver
Priority
✗throws NotSupportedException
Delay
✗published at once
Persistence
✓durable queue
Ack
✓ack after the handler

Amazon SQS

Class
AmazonSqsDriver
Priority
✗throws NotSupportedException
Delay
✗sent at once
Persistence
✓stored by SQS
Ack
✓deleted after the handler

✓ supported, ✗ not supported, ~ supported with a caveat. The notes below explain each cell.

Redis ext-redis notes ​

  • Priority. Each integer priority is a separate Redis set. wait() polls the highest number first. 5.x used reverse insertion order (issue #50).
  • Delay. A future executeAt goes into a sorted set with ZADD. Promotion uses ZREM on the member it just read. In 5.x it called SPOP and never promoted (#95).
  • Persistence. Whatever Redis is configured to do (RDB or AOF). Hermes does not set it. Values live in sets plus one sorted set.
  • Ack. There is no ack API. SPOP deletes the member, then the handler runs. A true or false return is ignored.

Predis notes ​

  • Priority. Same as Redis.
  • Delay. A future executeAt goes into a sorted set. Promotion uses ZREM on the member it just read.
  • Persistence. Same as Redis.
  • Ack. The same SPOP on the live set.

RabbitMQ lazy notes ​

  • Priority. setupPriorityQueue() throws NotSupportedException. send() ignores $priority.
  • Delay. executeAt stays in the JSON. basic_publish happens immediately.
  • Persistence. The queue is declared durable and messages are persistent (delivery_mode 2). Pass durable: false to keep a queue created by 5.x.
  • Ack. Manual. basic_ack after the handler, basic_nack with requeue when the callback fails, prefetch 1. 5.x used no_ack = true (#70).

Amazon SQS notes ​

  • Priority. Same as RabbitMQ. The exception text says AmazonSQS.
  • Delay. executeAt stays in the JSON. sendMessage happens immediately.
  • Persistence. SQS stores the body until this driver deletes it. The driver deletes after the callback returns. A failed handler leaves the message to reappear after the visibility timeout.
  • Ack. deleteMessage runs after unserialize and the callback succeed. Delivery is at least once. 5.x deleted before the handler (#69).

Within one Redis or Predis priority, order is not FIFO. A set has no order, and SPOP returns one random member.

Which file to copy ​

You haveStart from
phpredisRedis, examples/redis
PredisPredis, examples/predis
RabbitMQRabbitMQ, examples/rabbitmq
AWS SQSAmazon SQS, examples/sqs

Shutdown helpers are not drivers. SharedFileShutdown works with any driver. RedisShutdown needs ext-redis. PredisShutdown needs Predis. They are documented on Shutdown and max items.

FAQ ​

Which driver is the safest default? ​

PredisSetDriver. It needs no extension, supports priorities, and promotes delayed messages and retries. On 5.x it is the only driver that does.

Which driver keeps messages if a worker crashes? ​

From 6.0, LazyRabbitMqDriver and AmazonSqsDriver: they remove the message only after the handler finished. The Redis drivers pop it first. On 5.x none of them did. See Architecture.

Can the emitter and the worker use different drivers? ​

No. They must use the same driver class with the same keys, because the keys are the queue.

Does any driver support acknowledgements? ​

From 6.0, RabbitMQ acknowledges after the handler and SQS deletes after the handler. Redis pops the member first.

Is there a ZeroMQ driver? ​

It moved out of the package in 3.0.0, to tomaj/hermes-zmq-driver.

Released under the MIT License.