I'm experiencing an issue on the messenger component,
I have two messages classes and two handlers and when I execute
php bin/console debug:messenger
I get the these results:
As you can see in the two results I have different handler every time (DeliveryMQHandler
or OrderMQHandler
) but I need the both.
If someone got an idea this is my messenger configuration file :
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
routing:
# Route your messages to the transports
'App\Ressource\Message\Order\OrderMQ': async
'App\Ressource\Message\Delivery\DeliveryMQ': async
The DeliveryMQHandler :
<?php
namespace App\Ressource\Message\Handler;
use App\Ressource\Message\Delivery\DeliveryMQ;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
const XML_FOLDER = 'C:/tmp/';
class DeliveryMQHandler implements MessageHandlerInterface
{
public function __invoke(DeliveryMQ $deliveryMQ)
{
$fileName = 'LCT_GET_DELIVERY_LOCATION_'.date('Y-m-d').'_'.time().'_'.mt_rand(1000, 9999).'.xml';
$filePath = XML_FOLDER.$fileName;
$xml = $deliveryMQ->getContent();
$fileHandler = fopen($filePath, 'w+');
fwrite($fileHandler,$xml);
fclose($fileHandler);
return true;
}
}
The OrderMQHandler :
<?php
namespace App\Ressource\Message\Handler;
use App\Ressource\Message\Order\OrderMQ;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
const XML_FOLDER = 'C:/tmp/';
class OrderMQHandler implements MessageHandlerInterface
{
public function __invoke(OrderMQ $orderMQ)
{
$fileName = 'LCT_'.date('Y-m-d').'_'.time().'_'.mt_rand(1000, 9999).'.xml';
$filePath = XML_FOLDER.$fileName;
$xml = $orderMQ->getContent();
$fileHandler = fopen($filePath, 'w+');
fwrite($fileHandler,$xml);
fclose($fileHandler);
return true;
}
}
The message class are too big to show there but they are well implemented and I'm quite sure they are not the problem because the getContent()
method result is OK every time.
The autowiring property is set to true in the services.yml
The different class are well listed when I do the following command: php bin/console debug:container
Finnaly the stack trace of the error inside the php bin/console messenger:consume -vvv
:
EDIT : The structure of the two class => OrderMQ class :
<?php
namespace App\Ressource\Message\Order;
use App\Entity\Address;
use App\Entity\Customer;
use App\Entity\OrderHead;
use DOMDocument;
class OrderMQ {
private $content;
public function __construct(Customer $customer, Address $address, OrderHead $order)
{
//create the xml to send in the handler...
}
public function getContent() {
return $this->content;
}
/**
* @param string $content
* @return OrderMQ
*/
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}
DeliveryMQ class :
namespace App\Ressource\Message\Delivery;
use DOMDocument;
class DeliveryMQ {
private $content;
public function __construct($zipCode, $town)
{
//create the xml to send in the handler...
}
public function getContent() {
return $this->content;
}
/**
* @param string $content
* @return deliveryMQ
*/
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}