PHP code example of bam / php-publisher

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());
}

function __construct($receiverURL, $username, $password, $authenticationURL)

    @param string $receiverURL
    @param string $username
    @param string $password
    @param string $authenticationURL - @default null
  
function findStreamId($streamName, $streamVersion)
    
    @param string $streamName
    @param string $streamVersion
    @return string $streamId
    @throws NoStreamDefinitionExistException
    
function defineStream($streamDefinision)

    @param string $streamDefinision
    @return string $streamId
    @throws StreamDefinitionException
    @throws DifferentStreamDefinitionAlreadyDefinedException
    @throws MalformedStreamDefinitionException
    
function publish($event)
    @param Event $event
    @throws UnknownEventAttributeException    

function __construct($verifyPeer, $caFile)

    @param boolean $verifyPeer - @default false
    @param string $caFile - @default null
    @throws NullPointerException
    
function setVerifyPeer($verifyPeer)   
    @param boolean $verifyPeer

function getVerifyPeer()
    @return boolean $verifyPeer

function setCaFile($caFile)
    @param string $caFile
    
function getCaFile()    
    @return string $caFile

function __construct($streamId, $timeStamp, $metaData , $correlationData, $payloadData , $arbitraryDataMap)

    @param string $streamId - @default null
    @param string $timeStamp - @default null
    @param string $metaData - @default null
    @param array $correlationData - @default null
    @param array $payloadData - @default null
    @param array $arbitraryDataMap - @default null
    
function getStreamId()
    @return string $streamId
    
function setStreamId($streamId)
    @param string $streamId

function getTimeStamp()
    @return long $timeStamp
    
function setTimeStamp($timeStamp)
    @param long $timeStamp
    
function getMetaData()
    @return array $metaData
    
function setMetaData($metaData)
    @param array $metaData
    
function getCorrelationData()
    @return array $correlationData
    
function setCorrelationData($correlationData)
    @param array $correlationData
    
function getPayloadData()
    @return array $payloadData
    
function setPayloadData($payloadData)
    @param array $payloadData
    
function getArbitraryDataMap()
    @return array $arbitraryDataMap
    
function setArbitraryDataMap($arbitraryDataMap)
    @param array $arbitraryDataMap