-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleSystem.php
56 lines (50 loc) · 1.57 KB
/
SampleSystem.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
<?php
declare(strict_types=1);
namespace Example\Persistence;
use Phluxor\ActorSystem;
use Phluxor\Persistence\EventSourcedBehavior;
use Phluxor\Persistence\MySql\Connection;
use Phluxor\Persistence\MySql\DefaultSchema;
use Phluxor\Persistence\MySql\Dsn;
use Phluxor\Persistence\MySql\MysqlProvider;
use Psr\Log\LoggerInterface;
use Test\Persistence\ProtoBuf\TestMessage;
use function Swoole\Coroutine\run;
class SampleSystem
{
public function main(): void
{
run(function () {
\Swoole\Coroutine\go(function () {
$system = ActorSystem::create();
$props = ActorSystem\Props::fromProducer(fn() => new PersistenceActor(),
ActorSystem\Props::withReceiverMiddleware(
new EventSourcedBehavior(
$this->mysqlProvider($system->getLogger(), 3)
)
));
$ref = $system->root()->spawnNamed($props, 'test.actor');
$system->root()->send($ref->getRef(), new TestMessage(['message' => 'hello']));
});
});
}
private function mysqlProvider(
LoggerInterface $logger,
int $snapshotInterval
): MysqlProvider {
$conn = new Connection(
new Dsn(
'127.0.0.1',
3306,
'sample',
'user',
'passw@rd'
));
return new MysqlProvider(
$conn->proxy(),
new DefaultSchema(),
$snapshotInterval,
$logger
);
}
}