prolic / HumusAmqpModule

AMQP module for Zend Framework 2 to integrate RabbitMQ
https://humusamqp.readthedocs.io
MIT License
31 stars 13 forks source link

Migration from ZF2 to ZF3 #43

Closed marinovdf closed 7 years ago

marinovdf commented 7 years ago

I have migrated my app from ZF2 to ZF3, but HumusAmqpModule now is not working. I had version v0.3.1 before and config like this:

return [
    'controllers' => [
        'factories' => [
            TopicProducerController::class => TopicProducerControllerFactory::class,
        ]
    ],

    'humus_amqp_module' => [
        'exchanges' => [
            'opm-exchange' => [
                'name' => 'opm-exchange',
                'type' => 'direct',
                'arguments' => [],
            ],
            'demo.error' => [
                'name' => 'demo.error',
                'type' => 'direct',
                'arguments' => [],
            ],
        ],
        'queues' => [
            'opm-mail' => [
                'name' => 'opm-mail-queue',
                'exchange' => 'opm-exchange',
                'routing_keys' => [],
                'arguments' => [
                    'x-dead-letter-exchange' => 'demo.error' // must be defined as exchange before
                ],
                'bind_arguments' => [],
            ],
        ],
        'connections' => [
            'default' => [
                'host' => 'localhost',
                'port' => 5672,
                'login' => 'guest',
                'password' => 'guest',
                'vhost' => '/',
                'persistent' => true,
                'read_timeout' => 1, //sec, float allowed
                'write_timeout' => 1, //sec, float allowed
            ],
        ],
        'producers' => [
            'opm-producer' => [
                'exchange' => 'opm-exchange',
                'qos' => [
                    'prefetch_size' => 0,
                    'prefetch_count' => 10
                ],
                'auto_setup_fabric' => true
            ],
        ],
        'consumers' => [
            'opm-consumer' => [
                'queues' => [
                    'opm-mail'
                ],
                'auto_setup_fabric' => true,
                'callback' => 'mail',
                'idle_timeout' => 10,
                'logger' => 'consumer-logger',
                'error_callback' => 'errorcallback'
            ],
        ],

        'plugin_managers' => [
            'callback' => [
                'invokables' => [
                    'echo'          => EchoCallback::class,
                    'error'         => EchoErrorCallback::class,
                    'poweroftwo'    => PowerOfTwoCallback::class,
                    'randomint'     => RandomIntCallback::class,
                    'errorcallback' => ErrorCallback::class,
                ],

                'factories' => [
                    'mail' => MailCallbackFactory::class
                ]
            ]
        ]
    ],
];

After migration my composer.json looks like that:

{
  "require": {
    "php": "~7.0",
    "ext-amqp": ">=1.7.0",
    "ext-zip": "*",
    "ext-intl": "*",
    "ext-mbstring": "*",
    "ext-gd": "*",
    "ext-xml": "*",
    "ext-curl": "*",
    "ext-bcmath": "*",
    "roave/security-advisories": "dev-master",
    "zendframework/zendframework": "^3.0",
    "zendframework/zend-mvc-console": "^1.1",
    "phpoffice/phpexcel": "dev-master",
    "imagine/Imagine": "dev-master",
    "php-amqplib/php-amqplib": "2.6.2",
    "prolic/humus-amqp": "^1.1",
    "prolic/humus-amqp-module": "^1.0",
    ...
  }
}

Also in application.config.php in modules section added HumusAmqpModule

What I need to change to make everything work. Thanks.

marinovdf commented 7 years ago

I'he edited my config:

return [
    'controllers' => [
        'factories' => [
            TopicProducerController::class => TopicProducerControllerFactory::class,
        ]
    ],

    'dependencies' => [
        Driver::class => DriverFactory::class,
        'default-amqp-connection' => [ConnectionFactory::class, 'default'],
        'opm-consumer' => [CallbackConsumerFactory::class, 'opm-consumer'],
        'opm-producer' => [ProducerFactory::class, 'opm-producer'],
        'mail-callback' => MailCallbackFactory::class
    ],

    'humus' => [
        'amqp' => [
            'driver' => Driver::AMQP_EXTENSION,
            'connection' => [
                'default' => [
                    'host' => 'localhost',
                    'port' => 5672,
                    'login' => 'guest',
                    'password' => 'guest',
                    'vhost' => '/',
                    'persistent' => false,
                    'read_timeout' => 3,
                    'write_timeout' => 1
                ],
            ],
            'exchange' => [
                'opm-exchange' => [
                    'name' => 'opm-exchange',
                    'type' => 'direct',
                    'connection' => 'default-amqp-connection',
                    'auto_setup_fabric' => true,
                 ]
            ],
            'producer' => [
                'opm-producer' => [
                    'exchange' => 'opm-exchange',
                    'qos' => [
                        'prefetch_size' => 0,
                        'prefetch_count' => 10
                    ],
                    'auto_setup_fabric' => true
                ],
            ],
            'queue' => [
                'opm-mail' => [
                    'name' => 'opm-mail',
                    'exchanges' => [
                        'opm-exchange' => []
                    ],
                    'connection' => 'default-amqp-connection'
                ],
            ],
            'callback_consumer' => [
                'opm-consumer' => [
                    'queue' => 'opm-queue',
                    'idle_timeout' => 12.5,
                    'consumer_tag' => 'opm-consumer-tag',
                    'qos' => [
                        'prefetch_count' => 50,
                    ],
                ],
            ],
        ]
    ],
];

after run vendor/bin/humus-amqp-module setup-fabric fabric successfully installed. But after run vendor/bin/humus-amqp-module consumer -c opm-consumer I see No consumer with name opm-consumer found.

prolic commented 7 years ago

First note that TopicProducerController::class => TopicProducerControllerFactory::class is no more available.

Second, it should look like this:

'dependencies' => [
        'factories' => [
            // your factories here
        ]
]

It looks to me you put your factories not in the factories subconfig of dependencies.

marinovdf commented 7 years ago

Oh, yes, I've moved my factories to the factories subconfig, but still consumer does not found:

vagrant@host:/var/www$ vendor/bin/humus-amqp-module consumer -c opm-consumer
No consumer with name opm-consumer found
marinovdf commented 7 years ago

Maybe you have a small example?

prolic commented 7 years ago

There are examples in the documentation.

On May 30, 2017 18:50, "Dmitry Marinov" notifications@github.com wrote:

Maybe you have a small example?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/prolic/HumusAmqpModule/issues/43#issuecomment-304842561, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYEvMQKdTKPzIz_HGiGz0OAKqx0orvdks5r-_RggaJpZM4NpSJ- .

marinovdf commented 7 years ago

@prolic , thanks for your answers! My working config for ZF3 looks something like this (maybe someone will need):

return [
    'service_manager' => [
        'factories' => [
            Driver::class => DriverFactory::class,
            'default-amqp-connection' => [ConnectionFactory::class, 'default-amqp-connection'],
            'some-producer' => [ProducerFactory::class, 'some-producer'],
            'some-consumer' => [CallbackConsumerFactory::class, 'some-consumer'],
            MailCallback::class => MailCallbackFactory::class,
        ]
    ],

    'humus' => [
        'amqp' => [
            'driver' => Driver::PHP_AMQP_LIB,
            'connection' => [
                'default-amqp-connection' => [
                    'type' => 'socket', // only for php-amqplib driver
                    'host' => 'localhost',
                    'port' => 5672,
                    'login' => 'guest',
                    'password' => 'guest',
                    'vhost' => '/',
                    'persistent' => false,
                    'read_timeout' => 3,
                    'write_timeout' => 1
                ],
            ],
            'exchange' => [
                'some-exchange' => [
                    'name' => 'some-exchange',
                    'type' => 'direct',
                    'connection' => 'default-amqp-connection',
                    'auto_setup_fabric' => true,
                ]
            ],
            'producer' => [
                'some-producer' => [
                    'type' => 'json',
                    'exchange' => 'some-exchange',
                    'qos' => [
                        'prefetch_size' => 0,
                        'prefetch_count' => 10
                    ],
                    'auto_setup_fabric' => true
                ],
            ],
            'queue' => [
                'some-mail' => [
                    'name' => 'opm-mail',
                    'exchanges' => [
                        'some-exchange' => []
                    ],
                    'connection' => 'default-amqp-connection'
                ],
            ],
            'callback_consumer' => [
                'some-consumer' => [
                    'queue' => 'some-mail',
                    'delivery_callback' => MailCallback::class,
                    'idle_timeout' => 10,
                    'consumer_tag' => 'opm-consumer-tag',
                ],
            ],
        ]
    ],
];

The issue can be closed