BedrockStreaming / AmqpBundle

Amqp client as a Symfony Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Messages not published

akerouanton opened this issue · comments

Hi there,

I am trying to use a producer which is bound to direct exchange, but I am facing two bugs :

  • With the delivery_mode parameter set to persistent, it seems that the exchange never receive the messages.
  • And when this option is not use, whether the queue has been manually created (rabbitmqadmin declare exchange name='campaign_analysis' type='direct' && rabbitmqadmin declare queue name='campaign_analysis') or not, the first message is not published (but the following are correctly published). I've also tried with 'amq.direct' exchange, but I have the same behavior.

Here is my current config :

m6_web_amqp:
    event_dispatcher: false
    connections:
        default:
            host:     %amqp_host%
            port:     %amqp_port%
            timeout:  %amqp_timeout%
            login:    %amqp_user%
            password: %amqp_password%
            vhost:    %amqp_vhost%
            lazy:     false
    producers:
        campaign_analysis:
            connection: default
            exchange_options:
                name: 'campaign_analysis'
                type: direct
                routing_keys: ['campaign_analysis']
                publish_attributes:
                    content_type: 'application/json'
                    #delivery_mode: 'persistent'
    consumers:
        campaign_analysis:
            connection: default
            exchange_options:
                name: 'campaign_analysis'
            queue_options:
                name: 'campaign_analysis'
                durable: true
                routing_keys: ['campaign_analysis']

Any help would be appreciated :)

EDIT: I have tried this simple POC and it seems to work fine :

<?php

$conn = new AMQPConnection();
$conn->setHost('localhost');
$conn->setPort(5672);
$conn->setLogin('guest');
$conn->setPassword('guest');
$conn->setVhost('/');
$conn->connect();

$ch = new AMQPChannel($conn);

$ex = new AMQPExchange($ch);
$ex->setName('amq.direct');
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE);
$ex->declare();

$q = new AMQPQueue($ch);
$q->setName('campaign_analysis');
$q->declare();
$q->bind('amq.direct', 'campaign_analysis');

$ex->publish('Hi there!', 'campaign_analysis');

// var_dump($q->get(AMQP_AUTOACK));

hey @NiR-

are you still in troubles ?

So, it seems that :

  • You need to explicitly create the queue(s) before sending message to the exchange, in order to have messages correctly routed. So I am wondering why the queue configuration is at the consumer level and not producer.
  • The documentation is not up to date with the code : the delivery_mode parameter is not automatically converted from string to integer.

Hello,

There is no queue configuration at the producer level, only at the consumer level: the producer only need to know the routing keys to send a message to an exchange and many consumers can create many queues, listening to many routing keys, to receive the same message : ideally, the producer should not be responsible for creating the queues, only the consumers must - you don't know in advance what the consumers will do with these messages, do you ?

But you're right : if no queue exists for the routing keys, the message is lost. So feel free to add an optional queue configuration for the producer (to create a queue at producer level for example) ! We will be happy to add this feature.

Thank you again,

@fabdsp Now I known a little bit more about MQ, I agree with you that the producer shouldn't be responsible for creating the queues. So I propose to add a command that will create queues based on consumers configuration. In that way, consumers & producers can live in a separate application without sharing knowledge about each other. What do you think ?

@NiR- I'm not sure this kind of command should be in this bundle because the consumer's configuration can be outside the project (and not even written with php).

If you do something, maybe it's better to add an optional queue configuration for the producer if you really need it ? You will be sure that one queue is created at the time that the exchange and that no message is lost. What do you think about this ?

@NiR- An optional queue configuration for the producer is now available : #16