diff --git a/src/MessageBus/Handling/Handlers.php b/src/MessageBus/Handling/Handlers.php index b55ba5f..9aacd48 100644 --- a/src/MessageBus/Handling/Handlers.php +++ b/src/MessageBus/Handling/Handlers.php @@ -54,7 +54,6 @@ public function with(string $messageClass, callable $handler, string $qualifier } $copy = clone $this; - /** @phpstan-ignore assign.propertyType */ $copy->handlers[$messageClass][$qualifier] = $handler; return $copy; diff --git a/src/MessageBus/Pgmq/PgmqTransport.php b/src/MessageBus/Pgmq/PgmqTransport.php index 66bdca6..f806f3a 100644 --- a/src/MessageBus/Pgmq/PgmqTransport.php +++ b/src/MessageBus/Pgmq/PgmqTransport.php @@ -58,7 +58,9 @@ public function __construct( public function createQueue(string $name): void { Pgmq\createExtension($this->postgres); - Pgmq\createQueue($this->postgres, $name); + $queue = Pgmq\createQueue($this->postgres, $name); + + $queue->ensureNotifyInsert(); $this->postgres->query('create schema if not exists thesis_message_bus;'); $this->postgres->query( @@ -189,7 +191,10 @@ public function startConsumer(string $queue, ConsumerHandler $handler): PgmqCons $timeoutWatcher, new ChannelWatcher( $polls, - $this->postgres->listen($queue->enableNotifyInsert()), + // Not enableNotifyInsert(): recreating the trigger on every start took a table lock that waited for open + // producer transactions. ensureNotifyInsert() only reads the catalog when notifications are in place, + // and restores them when lost (the throttle table is UNLOGGED and is emptied by crash recovery). + $this->postgres->listen($queue->ensureNotifyInsert()), $timeoutWatcher, ), ]);