Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FarzadForuozanfar opened this issue Jun 30, 2024 · 1 comment

Comments

@FarzadForuozanfar
Copy link

FarzadForuozanfar commented Jun 30, 2024

<?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);
    }
}
@limingxinleo
Copy link
Member

You can try removed annotation #[Producer] from you class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants