params = $params; $this->messageBus = $messageBus; $this->logService = $logService; } /** * [ * - Send a message to Mercure's hub from topic that we want to subscribe. * - When message is private, it will be successfully proceed by messenger and queue. Althought it wont be send to the hub (Debugging Tools). * - It seems that Mercure will auto-generate a JWT (See Symfony\Component\Mercure\Hub.php publish method) maybe based on MERCURE_JWT_SECRET env var but according to symfony doc (https://symfony.com/doc/4.4/mercure.html#configuration), * this env var must be a JWT token and not a secret key => misunderstand cause with a secret key it will work instead of use a JWT signed with secret key ... * ] * * @param string|array $topics [description] * @param string|array $messages [description] * @param bool $private [description] * * @return void [description] */ public function publish($topics, $messages, ?bool $private = false): void { if (\is_array($topics) || \is_string($topics)) { if (\is_array($messages) || \is_string($messages)) { $update = new Update( $topics, json_encode($messages), $private ); // $this->hub->publish($update); // sync $this->logService->setLog('MercureHubService : DISPATCH on : ' . json_encode($topics)); $this->messageBus->dispatch($update, [new AmqpStamp('push_generation')]); // async } else { $error = "topics must be an array of strings or a string"; throw new InvalidArgumentException($error); } } else { $error = "messages must be an array of strings or a string"; throw new InvalidArgumentException($error); } } }