-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleClientTCPPublish.php
executable file
·91 lines (71 loc) · 3.06 KB
/
SampleClientTCPPublish.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
error_reporting(E_ALL);
include_once __DIR__ . '/vendor/autoload.php';
use org\wso2\carbon\databridge\commons\thrift\service\general\ThriftEventTransmissionServiceClient;
use publisher\Publisher;
use publisher\Event;
use publisher\PublisherConfiguration;
use publisher\PublisherConstants;
use publisher\StreamDefinitionException;
use publisher\NullPointerException;
$receiverURL = 'tcp://10.100.5.198:7611';
$authenticationURL = 'https://localhost:9443';
$username = 'admin';
$password = 'admin';
$verifyPeer = true;
$caFile = PublisherConstants::CAFILE_PATH;
try {
//Set configuration properties for the publisher
$configuration = new PublisherConfiguration($verifyPeer, $caFile);
//Initializing a Publisher object
$publisher = new Publisher($receiverURL, $username, $password, $authenticationURL, $configuration);
//JSON formatted stream definition
$streamDefinition = "{ 'name':'demo', "
."'version':'1.0.0', "
."'nickName':'Demo Stream 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);
echo $streamId.PHP_EOL;
//Searching a stream definition
$streamId = $publisher->findStreamId( "demo", "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){
var_dump($e);
}