Skip to content
Joshua Estes edited this page Oct 4, 2017 · 1 revision

Queue

All Queues share a common interface that allows you to use any queue type the exact same. Some queues have specific ways they do things, and those are documented in those sections. For this page, it's just going to be generic and not specific to any queue.

API

Each queue uses the same API.

getName()

The name of the queue can be retrieved with this method. Names are used internally to your app and should be unique.

$name = $queue->getName();

publish($message)

A $message can be either an object that implements a MessageInterface or one of the support Message Body types (array, string, object).

$queue->publish(['key' => $value]);
$queue->publish('Hello World');

$message = new Message();
$message->setBody('Hello World');
$queue->publish($message);

receive()

Receive a message out of the queue to be processed. If no messages are in the queue, this will return null.

// @var \Dspacelabs\Component\Queue\MessageInterface|null $message
$message = $queue->receive();

Another way to receive message is to use a loop.

while ($message = $queue->receive()) {
  // ... process message ...
}

delete(MessageInterface $message)

Clone this wiki locally