Skip to content

Commit 4020a3d

Browse files
authored
Use generated constants for message names (#300)
Use generated constants for message names, and newly created factories for message instantiation. Additionally, make sure that entity manager gets always cleared.
1 parent 2acbba4 commit 4020a3d

File tree

14 files changed

+77
-86
lines changed

14 files changed

+77
-86
lines changed

assets/js/Chat/Widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ customElements.define('chat-widget', class extends HTMLElement {
6060
this._input.addEventListener('keypress', this._onKeyPress.bind(this));
6161

6262
sse.subscribe(`chat-${chatId}`, {
63-
'Chat.MessageWritten': this._onMessageWritten.bind(this)
63+
'Chat.MessageWritten.v1': this._onMessageWritten.bind(this)
6464
}, this._sseAbortController.signal);
6565
}
6666

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"doctrine/doctrine-migrations-bundle": "^3.3",
3737
"doctrine/migrations": "^3.7",
3838
"doctrine/orm": "^3.0",
39-
"gaming-platform/api": "^1.4",
39+
"gaming-platform/api": "^1.5",
4040
"jms/serializer": "^3.17",
4141
"marein/php-nchan-client": "^3.1",
4242
"marein/symfony-lock-doctrine-migrations-bundle": "^1.0",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/chat/services/consumer.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
services:
22
chat.command-message-handler.topology:
33
class: Gaming\Common\MessageBroker\Integration\AmqpLib\Topology\QueueTopology
4-
arguments: ['Chat.CommandListener', 'gaming', ['Chat.InitiateChat']]
4+
arguments: ['Chat.CommandListener', 'gaming', [
5+
!php/const GamingPlatform\Api\Chat\V1\ChatV1::InitiateChatType
6+
]]
57
tags: [{ name: 'gaming.message-broker.topology' }]
68

79
chat.command-message-handler.consumer:
@@ -18,7 +20,9 @@ services:
1820

1921
chat.publish-to-browser-message-handler.topology:
2022
class: Gaming\Common\MessageBroker\Integration\AmqpLib\Topology\QueueTopology
21-
arguments: ['Chat.BrowserNotification', 'gaming', ['Chat.MessageWritten']]
23+
arguments: ['Chat.BrowserNotification', 'gaming', [
24+
!php/const GamingPlatform\Api\Chat\V1\ChatV1::MessageWrittenType
25+
]]
2226
tags: [{ name: 'gaming.message-broker.topology' }]
2327

2428
chat.publish-to-browser-message-handler.consumer:

config/identity/services/command_bus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ services:
1919

2020
identity.clear-manager-command-bus:
2121
class: Gaming\Common\Bus\Integration\DoctrineClearManagerBus
22-
decorates: 'identity.query-bus'
22+
decorates: 'identity.command-bus'
2323
arguments: ['@.inner', '@identity.doctrine-orm']

config/identity/services/consumer.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
services:
22
identity.bot-requests-message-handler.topology:
33
class: Gaming\Common\MessageBroker\Integration\AmqpLib\Topology\QueueTopology
4-
arguments: ['Identity.BotRequests', 'gaming', ['Identity.RegisterBot', 'Identity.GetBotByUsername']]
4+
arguments: ['Identity.BotRequests', 'gaming', [
5+
!php/const GamingPlatform\Api\Identity\V1\IdentityV1::RegisterBotType,
6+
!php/const GamingPlatform\Api\Identity\V1\IdentityV1::GetBotByUsernameType
7+
]]
58
tags: [{ name: 'gaming.message-broker.topology' }]
69

710
identity.bot-requests-message-handler.consumer:

src/Chat/Infrastructure/Messaging/PublishDomainEventsToMessageBrokerSubscriber.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Gaming\Common\EventStore\StoredEventSubscriber;
1111
use Gaming\Common\MessageBroker\Message;
1212
use Gaming\Common\MessageBroker\Publisher;
13+
use GamingPlatform\Api\Chat\V1\ChatV1;
1314

1415
final class PublishDomainEventsToMessageBrokerSubscriber implements StoredEventSubscriber
1516
{
@@ -37,8 +38,8 @@ private function handleMessageWritten(MessageWritten $event): void
3738
{
3839
$this->publisher->send(
3940
new Message(
40-
'Chat.MessageWritten',
41-
(new \GamingPlatform\Api\Chat\V1\MessageWritten())
41+
ChatV1::MessageWrittenType,
42+
ChatV1::createMessageWritten()
4243
->setChatId($event->aggregateId())
4344
->setMessageId((string)$event->messageId())
4445
->setAuthorId($event->authorId())

src/Chat/Infrastructure/Messaging/PublishMessageBrokerEventsToBrowserMessageHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Gaming\Common\MessageBroker\Message;
1010
use Gaming\Common\MessageBroker\MessageHandler;
1111
use Gaming\Common\Usernames\Usernames;
12-
use GamingPlatform\Api\Chat\V1\ChatV1Factory;
12+
use GamingPlatform\Api\Chat\V1\ChatV1;
1313

1414
final class PublishMessageBrokerEventsToBrowserMessageHandler implements MessageHandler
1515
{
@@ -22,14 +22,14 @@ public function __construct(
2222
public function handle(Message $message, Context $context): void
2323
{
2424
match ($message->name()) {
25-
'Chat.MessageWritten' => $this->handleMessageWritten($message),
25+
ChatV1::MessageWrittenType => $this->handleMessageWritten($message),
2626
default => true
2727
};
2828
}
2929

3030
private function handleMessageWritten(Message $message): void
3131
{
32-
$messageWritten = ChatV1Factory::createMessageWritten($message->body());
32+
$messageWritten = ChatV1::createMessageWritten($message->body());
3333

3434
$this->browserNotifier->publish(
3535
['chat-' . $message->streamId()],

src/Chat/Presentation/Messaging/CommandMessageHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use Gaming\Common\MessageBroker\Context;
1010
use Gaming\Common\MessageBroker\Message;
1111
use Gaming\Common\MessageBroker\MessageHandler;
12-
use GamingPlatform\Api\Chat\V1\ChatV1Factory;
13-
use GamingPlatform\Api\Chat\V1\InitiateChatResponse;
12+
use GamingPlatform\Api\Chat\V1\ChatV1;
1413

1514
final class CommandMessageHandler implements MessageHandler
1615
{
@@ -21,7 +20,7 @@ public function __construct(
2120

2221
public function handle(Message $message, Context $context): void
2322
{
24-
$request = ChatV1Factory::createInitiateChat($message->body());
23+
$request = ChatV1::createInitiateChat($message->body());
2524

2625
$chatId = $this->commandBus->handle(
2726
new InitiateChatCommand(
@@ -32,8 +31,8 @@ public function handle(Message $message, Context $context): void
3231

3332
$context->reply(
3433
new Message(
35-
'Chat.InitiateChatResponse',
36-
(new InitiateChatResponse())
34+
ChatV1::InitiateChatResponseType,
35+
ChatV1::createInitiateChatResponse()
3736
->setChatId($chatId)
3837
->setCorrelationId($request->getCorrelationId())
3938
->serializeToString()

src/Common/Bus/Integration/DoctrineClearManagerBus.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public function __construct(
1818

1919
public function handle(Request $request): mixed
2020
{
21-
$response = $this->bus->handle($request);
22-
23-
$this->manager->clear();
24-
25-
return $response;
21+
try {
22+
return $this->bus->handle($request);
23+
} finally {
24+
$this->manager->clear();
25+
}
2626
}
2727
}

0 commit comments

Comments
 (0)