contributte / rabbitmq

🐰 RabbitMQ (AMQP, STOMP, MQTT) using BunnyPHP for Nette Framework (@nette).
https://contributte.org/packages/contributte/rabbitmq.html
MIT License
24 stars 25 forks source link

nette-rabbitmq as internal 'extension' #18

Closed BigOHenry closed 5 years ago

BigOHenry commented 5 years ago

Hello, i have one problem with queue/consumer definition in config. If the configuration is in main config.neon (root/app/config/config.neon) everything is ok. But i need the configuration in different config (root/libs/Ext/src/DI/ext_config.neon). When i move it into 'extension' config it doesnt work:

Gamee\RabbitMQ\Producer\Exception\ProducerFactoryException
Producer [testProducer] does not exist

I have some parts of app like small extensions (root/libs). All services (consumer and queue) is at the same config (ext_config.neon) like configuration. Any way or ideas how this could work? Thank you very much

// root/libs/Ext/src/DI/ext_config.neon
services:
    # rabbitMQ
    - Ext\RabbitMq\Consumer\TestConsumer
    - Ext\RabbitMq\Queue\TestQueue(@Gamee\RabbitMQ\Client::getProducer(testProducer))

rabbitmq:
    connections:
        default:
            user: guest
            password: guest
            host: localhost
            port: 5672

    queues:
        testQueue:
            connection: default
            autoCreate: true

    producers:
        testProducer:
            queue: testQueue
            contentType: application/json
            deliveryMode: 2 # Producer::DELIVERY_MODE_PERSISTENT

    consumers:
        testConsumer:
            queue: testQueue
            callback: [@Ext\RabbitMq\Consumer\TestConsumer, consume]
            qos:
                prefetchSize: 0
                prefetchCount: 10
// root/libs/Ext/src/DI/ExtExtension.php
<?php

namespace Ext\DI;

use Nette;

class ExtExtension extends Nette\DI\CompilerExtension {

    public function loadConfiguration() {

        $config = $this->loadFromFile(__DIR__ . '/ext_config.neon');
        $config = Nette\DI\Helpers::expand($config, $this->validateConfig($this->config));

        Nette\DI\Compiler::loadDefinitions(
            $this->getContainerBuilder(),
            $config['services'],
            $this->name
        );
    }
}
BigOHenry commented 5 years ago

I solved it already.