Messages¶
Messages are objects that implement the PMG\Queue\Message
interface. These
objects are meant to be serializable and contain everything
you need for a handler to do its job.
A message to send an alert to a user might look something like this:
Example Message¶
<?php
use PMG\Queue\Message;
final class SendAlert implements Message
{
private $userId;
public function __construct($userId)
{
$this->userId = $userId;
}
public function getUserId()
{
return $this->userId;
}
}
Because messages are serialized to be put in a persistent backend they shouldn’t include objects that require state. In the example above the message just contains a user’s identifier rather than the full object. The handler would then look up the user.
See Consumers and Producers for more information about handlers and messages fit into the system as a whole.