Last active
June 1, 2017 14:55
-
-
Save kevinmlong/1e17d5e18fb9e279494ee247dfe61001 to your computer and use it in GitHub Desktop.
LetterCarrier for PHP Event Bus Using RabbitMQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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