Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.
Correlator Logic
Idea
The Idea of a correlator is to collect messages and RELIABLY relay them to (in the case of a process management system) to correct instances, or in other words: to the party that needs them.
- Some instances wait (now or in the future) for messages. Messages have to be stored and/or relayed when the instance is ready.
- Some messages may create new instances.
What to do?
- create the correlator.php that collects every input (use e.g. handleREST.php) and saves it to a LOG (also PUT/GET/POST/DELETE, all parameters and all headers).
- register correlator.php
- wait until you get some messages (and start the process)
- You should get messages every 30 minutes (including a 3 hour break between 5-8 in the morning)
- the messages (1) which you get should create an instance
- POST to https://cpee.org/flow/start/ with a parameter xml that contains the process template. This creates a process instance (2)
- the process runs then automatically, YOUR correlation.php gets a correlation message (2): a certain instance waits for a certain message.
- With the help of this correlation message, the correlator decides if a message is suitable for a certain instance.
- The correlation rule consists of:
- ID of an Instance (endpoint where to forward the message) - IF A MESSAGE ARRIVES, WHERE TO SEND IT?
- Critera - IF A MESSAGE ARRIVES, HOW TO FIND OUT TO WHOM I SHOULD FORWARD IT (e.g. has to contain an order number)
- If a rule applies (a certain message is identified to match a rule), it can be deleted (when the correlator is sure it arrived).
- Finally messages arrive (4)
Summary fuer correlator.php
- logs all messages
- instantiation message 4a creates new instance
- correlation messages 2 contain rules that are compared to all stored messages 4b. If no messages 4b are found, the rules from messages 2 are saved and compared to all messages 4 that arrive later.
How to post a file in PHP
Example using command line curl:
curl -X POST -H "Content-Type:text/xml" -H "Content-ID: xml" https://cpee.org/flow/start/ -d '[xml]'
directly run it after posting:
curl -X POST https://cpee.org/flow/start/xml/ -F 'behavior=wait_running' -F 'xml= [xml];type=text/xml'
Example using php curl («documentation»):
<?php
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "https://cpee.org/flow/start/");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Content-Type:text/xml','Content-ID:xml'));
$body = '<your_xml></your_xml>';
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($curl_handle);
if(curl_error($curl_handle)) {
print(curl_error($curl_handle));
}
else {
var_dump($result);
}
curl_close($curl_handle);
?>
Example using raw php:
<?php
$eol = "\r\n";
$mime_boundary=md5(time());
// $data .= '--' . $mime_boundary . $eol;
// $data .= 'Content-Disposition: form-data; name="inputfeld"' . $eol . $eol;
// $data .= "Meine Eingage" . $eol;
$data = '';
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="xml"; filename="filename.xml"' . $eol;
$data .= 'Content-Type: text/xml' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= chunk_split(base64_encode("<myxml>aaaa</myxml>")) . $eol; // mit file_get_contents von der platte holen
$data .= "--" . $mime_boundary . "--" . $eol . $eol; // zwei eol um server zu zeigen dass ich nix mehr senden will!
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary . $eol,
'content' => $data
));
header('content-type: text/plain');
$context = stream_context_create($opts);
$result = file_get_contents('https://cpee.org/flow/start/',false,$context);
print_r($result);
?>
Letzte Änderung: 17.06.2021, 13:24 | 487 Worte