Skip to content

Instantly share code, notes, and snippets.

@kevinmlong
Last active June 1, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmlong/1e17d5e18fb9e279494ee247dfe61001 to your computer and use it in GitHub Desktop.
Save kevinmlong/1e17d5e18fb9e279494ee247dfe61001 to your computer and use it in GitHub Desktop.
LetterCarrier for PHP Event Bus Using RabbitMQ
<?php
class LetterCarrier extends AbstractCarrier {
public function __construct($queueName = , $host = 'localhost', $port = 5672, $username = 'guest', $password = 'guest') {
parent::__construct($queueName, $host, $port, $username, $password);
}
protected function receivedParcel($msg) {
/* @param AMQPMessage $msg */
/* get the parcel by unserializing the meesage body */
$parcel = unserialize($msg->body);
/* check that the parcel is a Slack carrot */
if ($parcel instanceof Letter) {
/* @var $parcel \Franklin\Parcels\LetterParcel */
/* do stuff with parcel */
echo "The message in the letter is: {$parcel->getMessage()}";
}else{
echo 'The parcel is not a Letter. Unsure how to handle.';
}
// Acknowledge the message so that it's removed from the queue
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment