Process Rendering is applicable to queen processes (for continues processes), worker processes (one-time processes), and kannel handlers. Process will be rendered using config file called manifest and its process_type class file. Process should be install in its appropriate entity (queen, worker or kannel). Config file is rendering control that define what should be used and how to render the process. process_type class file is used to perform the defined process.
Below is as an example:
configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration id="stomp_receiver">
<section name="core">
<!-- Process Configuration-->
<config name="process">
<config name="type">stomp_receiver</config>
<config name="name">StompReceiver</config>
<config name="start">#TIMESTAMP FIRST TIME FOR EXECUTION#</config>
<config name="end">#TIMESTAMP LAST TIME FOR EXECUTION#</config>
</config>
<!--STOMP Connection-->
<config name="connections">
<config name="mainmq">
<config name="type">STOMP</config>
<config name="host">#IP TO YOUR STOMP SERVER#</config>
<config name="port">#PORT TO YOUR STOMP SERVER#</config>
<config name="username">#USERNAME TO LOG IN WITH#</config>
<config name="password">#PASSWORD TO LOG IN WITH#</config>
</config>
</config>
<!--Receive Topics-->
<config name="source">#TOPIC TO LISTEN ON#</config>
<config name="box">#BOX To PUT THE MESSAGE#</config>
<!--Queue Configuration-->
<config name="queue">
<config name="selectors">
<config name="{#SELECTOR NAME#}">
<config name="selector">
<config name="type">#TYPE OF SELECTORS#</config>
<config name="{}">#{}#</config>
</config>
<config name="storage">
<config name="type">#STORAGE TYPE#</config>
<config name="{}">{}</config>
</config>
</config>
</config>
</config>
</section>
</configuration>
processor file:
class stomp_receiver extends queenProcess {
/**
* queue
*
* @var object
*/
private $queue;
/**
* destination queue box
*
* @var string
*/
private $queueBox;
/**
* Configure process.
*
* @return void
*/
public function configure() {
$this->passage->mainmq->subscribe($this->config->source);
$this->queueBox = isset($this->config->box)?$this->config->box:'';
if (isset($this->config->system)) {
$system = $this->config->system;
if (isset($system->queue->config)) {
$file = isset($system->queue->config->file)?$system->queue->config->file:'';
if ($file!='' && $file==basename($file))
$file = CIISONLINE_System::GetSystemDir()
.'Configuration'.DIRECTORY_SEPARATOR.$file;
$section = isset($system->queue->config->section)?
$system->queue->config->section:null;
if (file_exists($file)) {
$sysQueueConfig = new CIISONLINE_Config_XML($file,$section);
$sysQueueConfig = $sysQueueConfig->getConfig();
CIISONLINE_Queue::$sysQueueConfig = $sysQueueConfig->router;
}
}
}
if (isset($this->config->queue)) {
if (isset($this->config->queue->ref)) {
$queueConfig = CIISONLINE_Queue::getRefConfig($this->config->queue->ref);
} else if (isset($this->config->queue->router))
$queueConfig = CIISONLINE_Queue::parseQueueConfig($this->config->queue->router);
else $queueConfig = false;
if ($queueConfig!==false
&& false!==($this->queue = CIISONLINE_Queue::createQueue($queueConfig))) {
} else {
$this->queen->controller->terminateProcesses($this);
}
} else {
$this->queen->controller->terminateProcesses($this);
}
}
/**
* If you overload queenProcess's onInit function, be sure to call
* onInit through queenProcess with the line:
* parent::onInit($config, $filename);
*
* If you neglect to do this, the queenProcess will load improperly and therefore
* not work correctly within a queen.
*
* @param object $config The configseed configuration handler
* @param string $filename The config file which generated this instance
*
* @return void
*/
public function onInit($config, $filename) {
parent::onInit($config, $filename);
$this->metrics['process.status'] = 'OK';
$this->configure();
}
/**
* If you overload queenProcess's onReconfigure function, be sure to call
* onReconfigure through queenProcess with the line:
* parent::onReconfigure($config, $filename);
*
* If you neglect to do this, the queenProcess will reload improperly and
* therefore stop working correctly within a queen.
*
* @param object $config The configseed configuration handler
* @param string $filename The config file which generated this instance
*
* @return void
*/
public function onReconfigure($config, $filename) {
parent::onReconfigure($config, $filename);
$this->metrics['process.status'] = 'OK';
$this->configure();
}
/**
* A required static breadcrumb which tells configseed what configuration
* options we should have.
*
* This is where you should mark options from your configuration file as
* either required (Necessary for your object to work) or optional (not
* necessary to functionality, but rather more fine-tune configuration).
*
* Be sure to call both queenProcess::docConfig() and passage::docConfig() with
* their proper options to ensure that you build an accurate map of options.
*
* @param object $config The configuration object
*
* @return void
*/
static public function docConfig(&$config) {
queenProcess::docConfig($config);
CIISONLINE_Passage::docConfig('mainmq', 'STOMP', $config);
$config->addOption('required', 'source', 'The topic to listen to');
$config->addOption('optional', 'box', 'The queue box to store');
}
/**
* This function waits for a message then logs it to the directory
* which is specified in the configs. If it cannot store the file, it
* logs an alert message.
*
* @param object $conn The STOMP connection
* @param object $msg The STOMP frame
*
* @return boolean true We want to ack the reception of the message, so we return true
*/
public function STOMP_OnMessage($conn, $msg){
$message = new CIISONLINE_Queue_Message($msg->headers,$msg->body);
if ((string)$this->queueBox!='')
$this->queue->putMessage($message,$this->queueBox);
else
$this->queue->putMessage($message);
CIISONLINE_Environment::Log()->info('', null, null, (__CLASS__)
, LOGGER_APPLICATION_CATEGORY, 'Stomp_Receiver: Writing a file to ' . $filename);
$this->metrics['transactions.count']++;
$this->lastexecution = time();
return true;
}
}
No comments:
Post a Comment