Exemplo n.º 1
0
 function SAPO_Broker_Tail($args = array())
 {
     $args = array_merge(array('max_lines_before_quit' => 0), $args);
     $this->debug = $args['debug'];
     $this->tailfile = $args['file'];
     SAPO_Broker::dodebug("SAPO_Broker_Tail innited with file " . $args['file']);
     $this->max_lines_before_quit = $args['max_lines_before_quit'];
     $this->publish_count = 0;
     $this->initted = TRUE;
 }
Exemplo n.º 2
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
#$broker=new SAPO_Broker(array('debug'=>TRUE,'force_streams'=>TRUE));
$broker = new SAPO_Broker();
// consumer example with periodic callbacks in main loop
echo "Subscribing topics\n";
$broker->subscribe('/sapo/blogs/activity/post', NULL, "processTopic1");
echo "Adding periodic callbacks to the main loop\n";
$broker->add_callback(array("sec" => 5), "periodicCalls");
$broker->add_callback(array("sec" => 10), "periodicCalls2");
echo "Starting consumer\n";
$broker->consumer();
echo "Consumer exited (last err: " . $broker->net->last_err . ")\n";
function periodicCalls()
{
    echo "Look mom, here I am\n";
}
function periodicCalls2()
{
    echo "Look mom, I'm here as well\n";
}
function processTopic1($payload, $topic, $net)
{
    echo "latest_status_timestamp_sent: " . $net->latest_status_timestamp_sent . "\n";
    echo "latest_status_timestamp_received: " . $net->latest_status_timestamp_received . "\n";
    echo "latest_status_message: " . $net->latest_status_message . "\n";
    echo "processTopic1() just got " . $payload . "\n";
}
Exemplo n.º 3
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
#$broker=new SAPO_Broker(array('debug'=>TRUE));
$broker = new SAPO_Broker();
// will use localhost
// this will be publish on the disks's dropbox because it's localhost
$r = $broker->publish('<xml>' . $broker->xmlentities('<<<ESCAPE-ME>>>') . '</xml>', array('topic' => '/sapo/developer/tests'));
if ($r == FALSE) {
    echo "Publish exited (last err: " . $broker->net->last_err . ")\n";
}
echo "Done\n";
Exemplo n.º 4
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
#$broker=new SAPO_Broker(array('debug'=>TRUE));
$broker = new SAPO_Broker();
// consumer example
echo "Subscribing topics\n";
$broker->subscribe('/sapo/tags/feeds/urls', NULL, "processUrls");
$broker->subscribe('/sapo/pesquisa/queries', NULL, "processSearch");
$broker->subscribe('/sapo/web/homepage/>', NULL, array("Test_Class", "processTests"));
echo "Entering consumer() loop now\n";
$broker->consumer();
echo "Consumer exited (last err: " . $broker->net->last_err . ")\n";
function processUrls($payload)
{
    echo "processUrls() just got " . $payload . "\n";
}
function processSearch($payload)
{
    echo "processSearch() just got " . $payload . "\n";
}
class Test_Class
{
    function processTests($payload)
    {
        echo "processTests() just got " . $payload . "\n";
    }
}
Exemplo n.º 5
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
$broker = new SAPO_Broker(array('debug' => TRUE));
#$broker=new SAPO_Broker;
// publish example
$r = $broker->publish('<xml>' . $broker->xmlentities('<<<ESCAPE-ME>>>') . '</xml>', array('topic' => '/testes/myqueue1', 'destination_type' => 'QUEUE'));
if ($r == FALSE) {
    echo "Publish exited (last err: " . $broker->net->last_err . ")\n";
}
echo "Done\n";
Exemplo n.º 6
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
if (!$argv[1]) {
    echo "Usage {$argv['0']} topic [QUEUE|TOPIC|TOPIC_AS_QUEUE]\n";
    exit;
}
#$broker=new SAPO_Broker(array('debug'=>TRUE));
$broker = new SAPO_Broker();
// consumer example
if ($argv[2]) {
    $broker->subscribe($argv[1], array('destination_type' => $argv[2]), "processExceptions");
} else {
    $broker->subscribe($argv[1], NULL, "processExceptions");
}
$broker->consumer();
function processExceptions($payload)
{
    echo $payload . "\n";
}
Exemplo n.º 7
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
#$broker=new SAPO_Broker(array('debug'=>TRUE));
$broker = new SAPO_Broker();
// publish example
$args['priority'] = 1;
$args['message_id'] = 1;
$args['persistent'] = 1;
$args['topic'] = '/sapo/developer/tests';
$r = $broker->publish('<xml>' . $broker->xmlentities('<<<ESCAPE-ME>>>') . '</xml>', $args);
if ($r == FALSE) {
    echo "Publish exited (last err: " . $broker->net->last_err . ")\n";
}
$args['topic'] = '/sapo/tags/sessions/users';
$r = $broker->publish('<xml>user has landed</xml>', $args);
if ($r == FALSE) {
    echo "Publish exited (last err: " . $broker->net->last_err . ")\n";
}
echo "Done\n";
Exemplo n.º 8
0
#!/usr/bin/php -q
<?php 
include '../classes/broker.php';
set_time_limit(0);
error_reporting(1);
$count = 0;
#$broker=new SAPO_Broker(array('debug'=>TRUE));
$broker = new SAPO_Broker(array('server' => '10.135.64.41', 'port' => 3322));
// consumer example
echo "Subscribing topics\n";
$broker->subscribe('/test/b', NULL, "processEvent");
echo "Entering consumer() loop now\n";
$broker->consumer();
echo "Consumer exited (last err: " . $broker->net->last_err . ")\n";
function processEvent($payload)
{
    global $count, $broker;
    echo "processEvent() just got " . $payload . "\n";
    $count++;
    if ($count == 10) {
        echo "Unsubsribing topic now\n";
        $broker->unsubscribe('/test/b');
    }
}