public function onMessageReceived(Wildfire_Message $message)
 {
     echo '<pre>';
     var_dump($message->getReceiver());
     var_dump(json_decode($message->getMeta(), true));
     var_dump(json_decode($message->getData(), true));
     echo '</pre>';
 }
Пример #2
0
 public function onMessageReceived(Wildfire_Message $message)
 {
     $data = Insight_Util::json_decode($message->getData());
     if (isset($data['authkey'])) {
         if (!isset($this->data['authkeys'])) {
             $this->data['authkeys'] = array();
         }
         $this->data['authkeys'][] = $data['authkey'];
     }
     if (isset($data['receivers'])) {
         if (!isset($this->data['receivers'])) {
             $this->data['receivers'] = array();
         }
         $this->data['receivers'] = array_merge($this->data['receivers'], $data['receivers']);
         array_unique($this->data['receivers']);
     }
 }
Пример #3
0
 public function testMultipleReceivers()
 {
     $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
     $dispatcher = new Wildfire_Dispatcher();
     $dispatcher->setChannel($channel);
     $message = new Wildfire_Message();
     $message->setData('Hello World');
     $message->setMeta('{"line":10}');
     $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
     $message->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
     $message->setReceiver('http://pinf.org/cadorn.org/fireconsole');
     $dispatcher->dispatch($message);
     $message->setReceiver('__TEST__');
     $dispatcher->dispatch($message);
     $channel->flush();
     $this->assertEquals(array('x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0', 'x-wf-1-index' => '2', 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole', 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php', 'x-wf-1-1-1-1' => '23|{"line":10}|Hello World|', 'x-wf-1-2-receiver' => '__TEST__', 'x-wf-1-2-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php', 'x-wf-1-2-1-2' => '23|{"line":10}|Hello World|'), $channel->getMessageParts());
 }
Пример #4
0
 public function dispatch(Wildfire_Message $message)
 {
     if (!$message->getProtocol()) {
         $message->setProtocol($this->protocol);
     }
     if (!$message->getSender()) {
         $message->setSender($this->sender);
     }
     if (!$message->getReceiver()) {
         $message->setReceiver($this->receiver);
     }
     $this->channel->enqueueOutgoing($message);
 }
Пример #5
0
 private function sendPointerMessage($channel, $key)
 {
     // pointer message should only be sent once
     if (isset($this->pointerMessages[$key])) {
         return;
     }
     // create a pointer message to be sent instead of the original messages
     $message = new Wildfire_Message();
     $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
     $message->setSender('http://registry.pinf.org/cadorn.org/wildfire/packages/lib-php/lib/Wildfire/Transport.php');
     $message->setReceiver(self::RECEIVER_ID);
     $message->setData(Wildfire_Util::json_encode($this->getPointerData($key)));
     // send the pointer message through the channel bypassing all transports and local receivers
     $channel->enqueueOutgoing($message, false, true);
     $this->pointerMessages[$key] = $message;
 }
Пример #6
0
 public function parse__enqueueMessage(&$messages, $index, $receiver, $sender, $value)
 {
     if (!$messages[$receiver]) {
         $messages[$receiver] = array();
     }
     preg_match_all('/^(.*?[^\\\\])?\\|(.*)$/', $value, $m);
     $message = new Wildfire_Message();
     $message->setReceiver($receiver);
     $message->setSender($sender);
     $message->setMeta($m[1][0] ? str_replace('&#124;', '|', $m[1][0]) : null);
     $message->setData(str_replace('&#124;', '|', $m[2][0]));
     $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
     $messages[$receiver][] = array($index, $message);
 }
Пример #7
0
 private function _parse_enqueueMessage(&$messages, $index, $value)
 {
     $receiver = "*";
     if (!isset($messages[$receiver])) {
         $messages[$receiver] = array();
     }
     $message = new Wildfire_Message();
     $message->setReceiver($receiver);
     preg_match_all('/^(.*?[^\\\\])?\\|(.*)$/si', $value, $m);
     $message->setMeta($m[1][0] || null);
     $message->setData($m[2][0]);
     $messages[$receiver][] = array($index, $message);
 }
Пример #8
0
 private function encode(Wildfire_Message $message)
 {
     $protocol_id = $message->getProtocol();
     if (!$protocol_id) {
         throw new Exception("Protocol not set for message");
     }
     return Wildfire_Protocol::factory($protocol_id)->encodeMessage($this->options, $message);
 }