0

我在信使组件上遇到问题,

我有两个消息类和两个处理程序,当我执行

php bin/console debug:messenger

我得到这些结果:

结果一

结果二

正如您在两个结果中看到的那样,我每次都有不同的处理程序(DeliveryMQHandlerOrderMQHandler),但我需要两者。

如果有人知道这是我的信使配置文件:

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

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;
        }
    }

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;
    }
}

消息类太大而无法在此处显示,但它们实现得很好,我很确定它们不是问题,因为getContent()方法结果每次都可以。

自动装配属性在 services.yml 中设置为 true 当我执行以下命令时,不同的类被很好地列出:php bin/console debug:container

最后是错误的堆栈跟踪php bin/console messenger:consume -vvv堆栈跟踪

编辑: 两个类的结构=> OrderMQ 类:

    <?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 类:

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;
    }
}
4

0 回答 0