Advertisement
Guest User

AMQP 1.0.5 Segfault

a guest
Aug 30th, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. <?php
  2.  
  3. class My_Queue_Amqp
  4. {
  5.     protected $_queueName = null;
  6.     protected $_exchangeName = 'RmqExchange';
  7.     protected $_servers;
  8.     protected $_connectedServer;
  9.     protected $_exchange;
  10.  
  11.     public function getQueueName()
  12.     {
  13.         if (true === is_null($this->_queueName)) {
  14.             throw new My_Queue_Amqp_Exception('No Queue name provided, please define in ' . get_class($this));
  15.         }
  16.  
  17.         return $this->_queueName;
  18.     }
  19.  
  20.     public function setQueueName($queueName)
  21.     {
  22.         $this->_queueName = $queueName;
  23.  
  24.         return $this;
  25.     }
  26.  
  27.     public function getExchangeName()
  28.     {
  29.         return $this->_exchangeName;
  30.     }
  31.  
  32.     public function setServers(array $servers)
  33.     {
  34.         $this->_servers = $servers;
  35.  
  36.         return $this;
  37.     }
  38.  
  39.     public function getServers()
  40.     {
  41.         return $this->_servers;
  42.     }
  43.  
  44.     public function connect()
  45.     {
  46.         foreach ($this->_servers as $server) {
  47.             try {
  48.                 $server->setExchangeName($this->getExchangeName());
  49.  
  50.                 $server->connect();
  51.  
  52.                 $this->_connectedServer = $server;
  53.  
  54.                 break;
  55.             } catch (Queue_Amqp_Server_Exception $e) {
  56.                 continue;
  57.             }
  58.         }
  59.  
  60.         if (false === isset($this->_connectedServer)) {
  61.             throw new My_Queue_Amqp_Exception('Unable to connect to server pool');
  62.         }
  63.  
  64.         return $this;
  65.     }
  66.  
  67.  
  68. }
  69.  
  70.  
  71. class My_Queue_Activity_Factory
  72. {
  73.     public function create()
  74.     {
  75.         $activity=new My_Queue_Amqp;
  76.         $servers=new My_Queue_Amqp_Server("localhost");
  77.  
  78.         $activity->setServers(array($servers));
  79.  
  80.         return $activity;
  81.     }
  82. }
  83.  
  84. class My_Queue_Amqp_Server
  85. {
  86.     protected $_exchange;
  87.  
  88.     public function setExchange(AMQPExchange $exchange)
  89.     {
  90.         $this->_exchange = $exchange;
  91.  
  92.         return $this;
  93.     }
  94.  
  95.     // commenting out this function causes segfault
  96.     public function getExchangeName()
  97.     {
  98.         return $this->_exchangeName;
  99.     }
  100.  
  101.     public function setExchangeName($exchangeName)
  102.     {
  103.         $this->_exchangeName = $exchangeName;
  104.  
  105.         return $this;
  106.     }
  107.  
  108.     public function getChannel()
  109.     {
  110.         return $this->_channel;
  111.     }
  112.  
  113.     public function setChannel($channel)
  114.     {
  115.         $this->_channel = $channel;
  116.  
  117.         return $this;
  118.     }
  119.  
  120.     public function connect()
  121.     {
  122.         $amqp = new AMQPConnection();
  123.  
  124.         $amqp->setHost("localhost");
  125.         $amqp->setLogin("guest");
  126.         $amqp->setPassword("guest");
  127.  
  128.         try {
  129.             $amqp->connect();
  130.             $this->setChannel(new AMQPChannel($amqp));
  131.         } catch (AMQPException $e) {
  132.             throw new My_Queue_Amqp_Server_Exception($e->getMessage());
  133.         }
  134.  
  135.         $exchange = new AMQPExchange($this->getChannel());
  136.         $exchange->setName($this->getExchangeName());
  137.         $exchange->setType(AMQP_EX_TYPE_TOPIC);
  138.         $exchange->declare();
  139.         $this->setExchange($exchange);
  140.         var_dump($exchange);
  141.         //throw new Exception("hello");
  142.  
  143.         // Exit causes segfault
  144.         exit;
  145.     }
  146.  
  147.  
  148. }
  149.  
  150. $factory = new My_Queue_Activity_Factory();
  151. $activity = $factory->create()->connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement