Created
June 9, 2015 23:26
-
-
Save videlalvaro/96cdba98f4f76e32b2b1 to your computer and use it in GitHub Desktop.
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 | |
include(__DIR__ . '/config.php'); | |
use PhpAmqpLib\Connection\AMQPConnection; | |
use PhpAmqpLib\Message\AMQPMessage; | |
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); | |
$ch = $conn->channel(); | |
$ch->queue_declare('test', false, true, false, false); | |
class A { | |
protected $a; | |
private $z = 0; | |
public function __construct($a) { | |
$this->a = $a; | |
} | |
protected function b() { | |
return $this->a * 2; | |
} | |
public function c() { | |
echo $this->b() + $this->z, "\n"; | |
} | |
} | |
$obj = new A(1); | |
echo "before serialize: ", $obj->c(); | |
$body = serialize($obj); | |
$msg = new AMQPMessage(serialize($obj)); | |
$ch->basic_publish($msg, '', 'test'); | |
echo "body sent: ", "\n", $body, "\n"; | |
function process_message($msg) { | |
echo "body received: ", "\n", $msg->body, "\n"; | |
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']); | |
$uns = unserialize($msg->body); | |
echo "after unserialize: ", $uns->c(); | |
} | |
$ch->basic_consume('test', '', false, true, false, false, 'process_message'); | |
// Loop as long as the channel has callbacks registered | |
while (count($ch->callbacks)) { | |
$ch->wait(); | |
} | |
$ch->close(); | |
$conn->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment