You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Joshua Estes edited this page Oct 4, 2017
·
3 revisions
Message
The Message object is the envelope that is used to send your 'message' to queues. Each Message has a body and attributes. The body is the text you want to publish to the queue. Some queues require attributes to help route that message.
Usage
<?phpuseDspacelabs\Component\Queue\Message;
$message = newMessage();
// The body can be almost anything like JSON text, arrays, or objects.$message->setBody($body);
// When you receive a message from the queue, you'll need to get the body// in order to process it.$body = $message->getBody();
// You can set one attribute at a time$message->addAttribute('key', $value);
// Set all attributes, which will overwrite any current attributes set on the message$message->setAttributes([
'key' => $value,
'key2' => $value2
]);
// Attributes also are put on message when you receive them, so once// you pull the message out of the queue ...$message = $queue->receive();
// ... you can get the value back$value = $message->getAttribute('key');
// ... you can see if the message has an attribute$hasAttribute = $message->hasAttribute('key');
// NOTE: Some queues add attributes when returning the message.