Skip to content

hi, hyperf is awesome framework im so thankful, but i have issue when produce message on RabbitMQ, i dont wanna re-declear exchange and queue  #20

@FarzadForuozanfar

Description

@FarzadForuozanfar
<?php

declare(strict_types=1);

namespace App\Amqp\Producer;

use Hyperf\Amqp\Message\ProducerMessage;
use Hyperf\Amqp\Annotation\Producer;

/**
 * @Producer(exchange="ex.priority", routingKey="priority", exchangeType="direct", durable=true)
 */
class SmsProducer extends ProducerMessage
{
    public function __construct($priority, $message)
    {
        $this->payload = $message;
        $this->setRoutingKey('priority' . $priority);
        $this->setExchange('ex.priority.' . $priority);
        $this->setType('direct');
    }

    public function getExchange(): string
    {
        return 'ex.priority.' . $this->getRoutingKeySuffix();
    }

    public function getRoutingKey(): string
    {
        return 'priority' . $this->getRoutingKeySuffix();
    }

    public function getQueue(): string
    {
        return 'q.priority.' . $this->getRoutingKeySuffix();
    }

    private function getRoutingKeySuffix(): string
    {
        return substr($this->routingKey, -1);
    }

    public function buildExchange(): void
    {
        // return (new ExchangeBuilder())
        //     ->withName($this->getExchange())
        //     ->withType('direct')
        //     ->withDurable(true);
    }

    public function buildQueue(): void
    {
        // return (new QueueBuilder())
        //     ->withName($this->getQueue())
        //     ->withDurable(true);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions