Fixed message parsing bug

This commit is contained in:
2024-03-01 21:48:28 +01:00
parent c4f3e8ae50
commit b2494c3163
3 changed files with 25 additions and 5 deletions

View File

@ -51,8 +51,10 @@ class CommandBus implements CommandBusInterface
$this->connections->attach($client);
$client->on('data', function ($data) use ($client) {
try {
$message = Message::fromString($data);
$this->onClientMessage($client, $message);
$messages = Message::fromStringMulti($data);
foreach ($messages as $message) {
$this->onClientMessage($client, $message);
}
} catch (MessageException $e) {
$client->end('{"msg":"error","data":{"error":"Bad message format"}}');
}
@ -71,6 +73,9 @@ class CommandBus implements CommandBusInterface
$this->executeContext($context)->then(
function ($result) use ($message, $client) {
$client->write($message->asResult($result)->toJson()."\n");
},
function (\Throwable $error) use ($message, $client) {
$client->write($message->asError($error->getMessage())->toJson()."\n");
}
);
break;