if ($adapter->connect()) { echo "[Success] [connect to meta] [{$adapter->meta_name}]\n"; } else { echo "[Failure] [{$adapter->last_error_message}]\n"; } // 准备bigpipe stomp $stomp_conf = new BigpipeStompConf(); $stomp_conf->conn_conf->try_time = 1; $stomp = new BigpipeStompAdapter($stomp_conf); // 发布/订阅参数 $pipe_name = 'pipe1'; $pipelet_id = 2; // 加1在哪里做好呢? $start_point = -1; // 取得可发布broker $broker = $adapter->get_pub_broker($pipe_name, $pipelet_id); if (false === $broker) { echo "[Failure][get pub info]\n"; } else { echo "[Success][get pub info]\n"; // 向broker发起连接请求 $pub_dest = array("socket_address" => $broker['ip'], "socket_port" => $broker['port'], "socket_timeout" => 300); $stomp->set_destination($pub_dest); $stomp->role = BStompRoleType::PUBLISHER; $stomp->topic_name = $broker['stripe']; $stomp->session_id = BigpipeUtilities::get_pipelet_name($pipe_name, $pipelet_id) . '_' . BigpipeUtilities::get_uid(); if ($stomp->connect()) { echo '[Success][connected on broker][ip:' . $broker['ip'] . '][port:' . $broker['port'] . ']\\n'; echo '[session message id][' . $stomp->session_message_id . ']\\n'; } echo "\n";
public function testGetPubBroker() { $subject = new MetaAgentAdapter(); $pipe_name = 'pipe'; $pipelet_id = 2; // 测试1 从还未被初始化的对象调用接口 $this->assertFalse($subject->get_pub_broker($pipe_name, $pipelet_id)); // 测试2 meta name为空 $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true)); $this->assertFalse($subject->get_pub_broker(null, $pipelet_id)); // mock connection 行为 // 定义connection行为 $this->stub_conn->expects($this->any())->method('is_connected')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('create_connection')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('send')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('close'); $ack_pkgs = $this->_gen_get_pubinfo_ack(); $this->stub_conn->expects($this->any())->method('receive')->will($this->onConsecutiveCalls(null, $ack_pkgs['bad'], $ack_pkgs['good'])); $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn)); // 测试2.2 request null $subject->meta_name = 'meta'; $this->assertFalse($subject->get_pub_broker($pipe_name, $pipelet_id)); // 测试2.3 ack wrong pakcage $this->assertFalse($subject->get_pub_broker($pipe_name, $pipelet_id)); // 测试2.4 成功 $broker = $subject->get_pub_broker($pipe_name, $pipelet_id); $this->assertTrue(false != $broker); $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', false)); }