1. Go to this page and download the library: Download bam/php-publisher library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bam / php-publisher example snippets
$receiverURL = 'tcp://10.100.5.198:7761';
$authenticationURL = 'https://localhost:9443';
$username = 'admin';
$password = 'admin';
$verifyPeer = true;
$caFile = '/absolute/path/to/certificate.pem';
try {
//Set configuration properties for the publisher
$config = new PublisherConfiguration($verifyPeer, $caFile);
//Initializing a Publisher object
$publisher = new Publisher($receiverURL, $username, $password, $authenticationURL, $config);
//JSON formatted stream definition
$streamDefinition = "{ 'name':'sample.stream', "
."'version':'1.0.0', "
."'nickName':'Sample Saream Definition',"
."'description':'This is a description',"
."'metaData':[{'name':'metaField1','type':'STRING'}],"
."'correlationData':[{'name':'corrField1','type':'STRING'}],"
."'payloadData':[{'name':'payloadField1','type':'STRING'},"
."{'name':'payloadField2','type':'DOUBLE'},"
."{'name':'payloadField3','type':'STRING'},"
."{'name':'payloadField4','type':'INT'} ] }";
//Adding the strem definition to BAM
$streamId = $publisher->defineStream($streamDefinition);
//Searching a stream definition
$streamId = $publisher->findStream( 'sample.stream', '1.0.0' );
//Initializing an Event object
$event = new Event($streamId, time());
//Setting up event attributes. The of each array should follow the data type and order of the stream definiiton
$metaData = ['meta1'];
$correlationData = ['corr1'];
$payloadData = ['pay1',pi(),'pay2',888];
$arbitraryDataMap = ['x'=>'arb1','y'=>'arb2'];
//Adding the attributes to the Event object
$event->setMetaData($metaData);
$event->setCorrelationData($correlationData);
$event->setPayloadData($payloadData);
$event->setArbitraryDataMap($arbitraryDataMap);
//Publish the event to BAM
$publisher->publish($event);
}catch(Exception $e){
//To see the exception types supported by the publisher, refer the API section
print_r($e->getTrace());
}