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 . " "; echo $susi->unregisterProcessor($reg_1_id); echo $susi->unregisterProcessor($reg_2_id); // should fail //echo "unregister ".$reg_1_id. " ";
* 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 { echo "FAILED \n"; } // add some header infos $event->setHeader(array("added Header" => "by processor 1")); // get payload $payload = $event->getPayload(); // add payload $payload["add_one"] = $payload["number"] + 1; $payload["test_payload"] = "ok1"; $event->setPayload($payload); }); $p2 = $susi->registerProcessor("test_event", function (&$event) use($susi) { echo "processor 2 handler called "; $data = $event->getData(); // test event data from processor 1 if (isset($data["payload"]["test_payload"]) && $data["payload"]["test_payload"] == "ok1" && count($data["headers"]) == 2) { echo "OK \n"; } else {