-
Notifications
You must be signed in to change notification settings - Fork 31
/
demo-async-dns-cluster.php
102 lines (74 loc) · 2.53 KB
/
demo-async-dns-cluster.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
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* This file is part of the prooph/event-store-client.
* (c) 2018-2018 prooph software GmbH <contact@prooph.de>
* (c) 2018-2018 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Prooph\EventStoreClient;
use Amp\Loop;
require __DIR__ . '/../vendor/autoload.php';
Loop::run(function () {
$builder = new ConnectionSettingsBuilder();
$builder->setClusterDns('escluster.net');
$builder->setClusterGossipPort(2113);
$connection = EventStoreAsyncConnectionBuilder::createFromSettings(
null,
$builder->build(),
'dns-cluster-connection'
);
$connection->onConnected(function (): void {
echo 'connected' . PHP_EOL;
});
$connection->onClosed(function (): void {
echo 'connection closed' . PHP_EOL;
});
yield $connection->connectAsync();
$slice = yield $connection->readStreamEventsForwardAsync(
'foo-bar',
10,
2,
true
);
\var_dump($slice);
$slice = yield $connection->readStreamEventsBackwardAsync(
'foo-bar',
10,
2,
true
);
\var_dump($slice);
$event = yield $connection->readEventAsync('foo-bar', 2, true);
\var_dump($event);
$m = yield $connection->getStreamMetadataAsync('foo-bar');
\var_dump($m);
$r = yield $connection->setStreamMetadataAsync('foo-bar', ExpectedVersion::ANY, new StreamMetadata(
null, null, null, null, null, [
'foo' => 'bar',
]
));
\var_dump($r);
$m = yield $connection->getStreamMetadataAsync('foo-bar');
\var_dump($m);
$wr = yield $connection->appendToStreamAsync('foo-bar', ExpectedVersion::ANY, [
new EventData(EventId::generate(), 'test-type', false, 'jfkhksdfhsds', 'meta'),
new EventData(EventId::generate(), 'test-type2', false, 'kldjfls', 'meta'),
new EventData(EventId::generate(), 'test-type3', false, 'aaa', 'meta'),
new EventData(EventId::generate(), 'test-type4', false, 'bbb', 'meta'),
]);
\var_dump($wr);
$ae = yield $connection->readAllEventsForwardAsync(Position::start(), 2, false, new UserCredentials(
'admin',
'changeit'
));
\var_dump($ae);
$aeb = yield $connection->readAllEventsBackwardAsync(Position::end(), 2, false, new UserCredentials(
'admin',
'changeit'
));
\var_dump($aeb);
$connection->close();
});