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-redis | Predis | RabbitMQ lazy | Amazon SQS | |
|---|---|---|---|---|
| Class | RedisSetDriver | PredisSetDriver | LazyRabbitMqDriver | AmazonSqsDriver |
| 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
executeAtgoes into a sorted set withZADD. Promotion usesZREMon the member it just read. In 5.x it calledSPOPand 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.
SPOPdeletes the member, then the handler runs. Atrueorfalsereturn is ignored.
Predis notes
- Priority. Same as Redis.
- Delay. A future
executeAtgoes into a sorted set. Promotion usesZREMon the member it just read. - Persistence. Same as Redis.
- Ack. The same
SPOPon the live set.
RabbitMQ lazy notes
- Priority.
setupPriorityQueue()throwsNotSupportedException.send()ignores$priority. - Delay.
executeAtstays in the JSON.basic_publishhappens immediately. - Persistence. The queue is declared durable and messages are persistent (
delivery_mode2). Passdurable: falseto keep a queue created by 5.x. - Ack. Manual.
basic_ackafter the handler,basic_nackwith requeue when the callback fails, prefetch 1. 5.x usedno_ack = true(#70).
Amazon SQS notes
- Priority. Same as RabbitMQ. The exception text says
AmazonSQS. - Delay.
executeAtstays in the JSON.sendMessagehappens 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.
deleteMessageruns 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 have | Start from |
|---|---|
| phpredis | Redis, examples/redis |
| Predis | Predis, examples/predis |
| RabbitMQ | RabbitMQ, examples/rabbitmq |
| AWS SQS | Amazon 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.