-
Notifications
You must be signed in to change notification settings - Fork 31
/
demo-async-with-logger.php
101 lines (73 loc) · 2.61 KB
/
demo-async-with-logger.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
<?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->enableVerboseLogging();
$builder->useConsoleLogger();
$connection = EventStoreAsyncConnectionBuilder::createFromIpEndPoint(
new IpEndPoint('eventstore', 1113),
$builder->build()
);
$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(\get_class($slice));
$slice = yield $connection->readStreamEventsBackwardAsync(
'foo-bar',
10,
2,
true
);
\var_dump(\get_class($slice));
$event = yield $connection->readEventAsync('foo-bar', 2, true);
\var_dump(\get_class($event));
$m = yield $connection->getStreamMetadataAsync('foo-bar');
\var_dump(\get_class($m));
$r = yield $connection->setStreamMetadataAsync('foo-bar', ExpectedVersion::ANY, new StreamMetadata(
null, null, null, null, null, [
'foo' => 'bar',
]
));
\var_dump(\get_class($r));
$m = yield $connection->getStreamMetadataAsync('foo-bar');
\var_dump(\get_class($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(\get_class($wr));
$ae = yield $connection->readAllEventsForwardAsync(Position::start(), 2, false, new UserCredentials(
'admin',
'changeit'
));
\var_dump(\get_class($ae));
$aeb = yield $connection->readAllEventsBackwardAsync(Position::end(), 2, false, new UserCredentials(
'admin',
'changeit'
));
\var_dump(\get_class($aeb));
$connection->close();
});