Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class My_Queue_Amqp
- {
- protected $_queueName = null;
- protected $_exchangeName = 'RmqExchange';
- protected $_servers;
- protected $_connectedServer;
- protected $_exchange;
- public function getQueueName()
- {
- if (true === is_null($this->_queueName)) {
- throw new My_Queue_Amqp_Exception('No Queue name provided, please define in ' . get_class($this));
- }
- return $this->_queueName;
- }
- public function setQueueName($queueName)
- {
- $this->_queueName = $queueName;
- return $this;
- }
- public function getExchangeName()
- {
- return $this->_exchangeName;
- }
- public function setServers(array $servers)
- {
- $this->_servers = $servers;
- return $this;
- }
- public function getServers()
- {
- return $this->_servers;
- }
- public function connect()
- {
- foreach ($this->_servers as $server) {
- try {
- $server->setExchangeName($this->getExchangeName());
- $server->connect();
- $this->_connectedServer = $server;
- break;
- } catch (Queue_Amqp_Server_Exception $e) {
- continue;
- }
- }
- if (false === isset($this->_connectedServer)) {
- throw new My_Queue_Amqp_Exception('Unable to connect to server pool');
- }
- return $this;
- }
- }
- class My_Queue_Activity_Factory
- {
- public function create()
- {
- $activity=new My_Queue_Amqp;
- $servers=new My_Queue_Amqp_Server("localhost");
- $activity->setServers(array($servers));
- return $activity;
- }
- }
- class My_Queue_Amqp_Server
- {
- protected $_exchange;
- public function setExchange(AMQPExchange $exchange)
- {
- $this->_exchange = $exchange;
- return $this;
- }
- // commenting out this function causes segfault
- public function getExchangeName()
- {
- return $this->_exchangeName;
- }
- public function setExchangeName($exchangeName)
- {
- $this->_exchangeName = $exchangeName;
- return $this;
- }
- public function getChannel()
- {
- return $this->_channel;
- }
- public function setChannel($channel)
- {
- $this->_channel = $channel;
- return $this;
- }
- public function connect()
- {
- $amqp = new AMQPConnection();
- $amqp->setHost("localhost");
- $amqp->setLogin("guest");
- $amqp->setPassword("guest");
- try {
- $amqp->connect();
- $this->setChannel(new AMQPChannel($amqp));
- } catch (AMQPException $e) {
- throw new My_Queue_Amqp_Server_Exception($e->getMessage());
- }
- $exchange = new AMQPExchange($this->getChannel());
- $exchange->setName($this->getExchangeName());
- $exchange->setType(AMQP_EX_TYPE_TOPIC);
- $exchange->declare();
- $this->setExchange($exchange);
- var_dump($exchange);
- //throw new Exception("hello");
- // Exit causes segfault
- exit;
- }
- }
- $factory = new My_Queue_Activity_Factory();
- $activity = $factory->create()->connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement