B
B
buranich2014-01-29 12:59:30
PHP
buranich, 2014-01-29 12:59:30

PHP + ZeroMQ, how not to lose messages if PULL worker crashes?

Hello!
I use ZeroMQ with the PUSH-PULL pattern in order to receive a request from the client and instantly send a page about the success of the operation to the browser, and at this time transfer all the "hard" work to the worker.
It looks like this. Customer:

$pusher = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$pusher->bind("tcp://*:5557");
$pusher->send("My message", ZMQ::MODE_DONTWAIT);

Worker:
$receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->connect("tcp://localhost:5557");
while (true) {
    $string = $receiver->recv();
    // ...
}

The problem arises if the worker crashes. In this case, the client sends a message to no one knows where, and when restarted, the worker does not receive these messages.
How to be in this situation? What is the correct way to "buffer" messages even if the worker has crashed?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sardar, 2014-01-29
@Sardar

Maybe you should use a persistent queue like RabbitMQ ? There is no size limit for messages and they are saved until they are consumed. Moreover, the message is reserved while the worker is executing the task and is either removed from the queue upon successful completion, or returned to the queue if the worker died quietly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question