-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
31 lines (25 loc) · 870 Bytes
/
client.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
<?php
use Cooper\CanalClient\CanalClient;
use Cooper\CanalClient\CanalConnectorFactory;
use Cooper\CanalClient\Fmt;
require_once __DIR__ . '/../vendor/autoload.php';
ini_set('display_errors', 'On');
error_reporting(E_ALL);
try {
// $client = CanalConnectorFactory::createClient(CanalClient::TYPE_SOCKET_CLUE);
$client = CanalConnectorFactory::createClient(CanalClient::TYPE_SWOOLE);
$client->connect("127.0.0.1", 11111);
$client->subscribe("1001", "example", ".*\\..*");
# $client->subscribe("1001", "example", "db_name.tb_name"); # 设置过滤
while (true) {
$message = $client->get(100);
if ($entries = $message->getEntries()) {
foreach ($entries as $entry) {
Fmt::println($entry);
}
}
sleep(1);
}
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
}