Exemple #1
0
function __autoload($name)
{
    $paths = explode(PATH_SEPARATOR, get_include_path());
    array_push($paths, dirname(__FILE__));
    array_push($paths, dirname(__FILE__) . "/ION");
    array_push($paths, dirname(__FILE__) . "/vendor");
    set_include_path(implode(PATH_SEPARATOR, $paths));
    $name = implode("/", explode("_", $name)) . ".php";
    require $name;
}
$config = '/mnt/data/web/config.php';
if (!file_exists($config)) {
    $config = _DIR . '/config.php';
}
require $config;
$susi = new Susi($CONFIG["SUSI_ADDR"], $CONFIG["SUSI_PORT"], true);
$container = new IONContainer($CONFIG);
$reg_1_id = $susi->registerProcessor("test_controller", function (&$event) use($susi, $container) {
    if (isset($event["data"]["payload"])) {
        $event["data"]["payload"]["test1"] = "ok";
    }
});
$reg_2_id = $susi->registerProcessor("test_controller", function (&$event) use($susi, $container) {
    if (isset($event["data"]["payload"])) {
        $event["data"]["payload"]["test2"] = "ok";
    }
    $susi->publish("lala", array("PUP" => "FROM P2"), function ($event) use($susi, $container) {
        echo "finished \n";
    });
});
echo "unregister " . $reg_1_id . " ";
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * @author: Thomas Krause (thomas.krause@webvariants.de)
 */
// INFO
// pass $event in processor and consumer handler as reference !!!
define("_DIR", dirname(__FILE__));
require _DIR . '/../Susi.php';
require _DIR . '/../config.php';
/*
 * create Susi Instance
 */
$susi = new Susi($CONFIG["SUSI_ADDR"], $CONFIG["SUSI_PORT"], false);
/*
 *  Register Processors
 * 
 * @param string           Eventname
 * @param function($event) Handler, for processor logic
 *
 * @return interger        unique EventID, can be used for unregister 
 */
$p1 = $susi->registerProcessor("test_event", function (&$event) use($susi) {
    echo "processor 1 handler called ";
    $data = $event->getData();
    // test event data from publish
    if (isset($data["payload"]["number"]) && $data["payload"]["number"] == 1 && count($data["headers"]) == 1) {
        echo "OK \n";
    } else {