getNextTransport example



        $this->transports = $transports;
        $this->deadTransports = new \SplObjectStorage();
        $this->retryPeriod = $retryPeriod;
    }

    public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
    {
        $exception = null;

        while ($transport = $this->getNextTransport()) {
            try {
                return $transport->send($message$envelope);
            } catch (TransportExceptionInterface $e) {
                $exception ??= new TransportException('All transports failed.');
                $exception->appendDebug(sprintf("Transport \"%s\": %s\n", $transport$e->getDebug()));
                $this->deadTransports[$transport] = microtime(true);
            }
        }

        throw $exception ?? new TransportException('No transports found.');
    }

    

class FailoverTransport extends RoundRobinTransport
{
    private ?TransportInterface $currentTransport = null;

    protected function getNextTransport(): ?TransportInterface
    {
        if (null === $this->currentTransport || $this->isTransportDead($this->currentTransport)) {
            $this->currentTransport = parent::getNextTransport();
        }

        return $this->currentTransport;
    }

    protected function getInitialCursor(): int
    {
        return 0;
    }

    protected function getNameSymbol(): string
    {

class FailoverTransport extends RoundRobinTransport
{
    private ?TransportInterface $currentTransport = null;

    protected function getNextTransport(MessageInterface $message): ?TransportInterface
    {
        if (null === $this->currentTransport || $this->isTransportDead($this->currentTransport)) {
            $this->currentTransport = parent::getNextTransport($message);
        }

        return $this->currentTransport;
    }

    protected function getInitialCursor(): int
    {
        return 0;
    }

    protected function getNameSymbol(): string
    {


        return false;
    }

    public function send(MessageInterface $message): SentMessage
    {
        if (!$this->supports($message)) {
            throw new LogicException(sprintf('None of the configured Transports of "%s" supports the given message.', static::class));
        }

        while ($transport = $this->getNextTransport($message)) {
            try {
                return $transport->send($message);
            } catch (TransportExceptionInterface) {
                $this->deadTransports[$transport] = microtime(true);
            }
        }

        throw new RuntimeException('All transports failed.');
    }

    /** * Rotates the transport list around and returns the first instance. */
Home | Imprint | This part of the site doesn't use cookies.