prolic / HumusAmqp

PHP 7.4 AMQP library
https://humusamqp.readthedocs.io/
MIT License
76 stars 17 forks source link

Need help to get a queue object #33

Closed alexz707 closed 7 years ago

alexz707 commented 7 years ago

Hi! First of all great work!! Keep it up ;) I have a little problem with the QueueFactory (or I simply don't get it):

I want to fetch a queue object via $container->get() (in ZF3). In my conf I have the following entry:

'service_manager' => [
    'factories' => [ 'queueExample' => [QueueFactory::class, 'queueExample'] ],
]

in my factory I wanted to get the queue:
$container->get('queueExample')

It doesn't work, it throws the following error: Zend\ServiceManager\Exception\ServiceNotCreatedException: Service with name "queueExample" could not be created. Reason: The second argument must be a type of Humus\Amqp\Channel or null

When I try it with the invoke method it works of course (so it's not a config problem ;) ) Can you please tell me how to retrieve this queue? Or is this not supposed to be called that way?

Thanks! Alex

prolic commented 7 years ago

The queue factory is only for internal use (f.e. for consumer, rpc server). It's not meant to be used by the user himself.

But you can create a queue very simple by calling:

$queue = $channel->newQueue();

By the way, why do you want to use the queue directly and not the provided consumer implementation?

Am 03.04.2017 21:14 schrieb "Al3x Zamponi" notifications@github.com:

Hi! First of all great work!! Keep it up ;) I have a little problem with the QueueFactory (or I simply don't get it):

I want to fetch a queue object via $container->get() (in ZF3). In my conf I have the following entry:

'service_manager' => [ 'factories' => [ 'queueExample' => [QueueFactory::class, 'queueExample'] ], ]

in my factory I wanted to get the queue: $container->get('queueExample')

It doesn't work, it throws the following error: Zend\ServiceManager\Exception\ServiceNotCreatedException: Service with name "queueExample" could not be created. Reason: The second argument must be a type of Humus\Amqp\Channel or null

When I try it with the invoke method it works of course (so it's not a config problem ;) ) Can you please tell me how to retrieve this queue? Or is this not supposed to be called that way?

Thanks! Alex

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/prolic/HumusAmqp/issues/33, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYEvHGXZJAzkL4z5a8p7KoRcFQV3Nsuks5rsPCtgaJpZM4MxhN6 .

alexz707 commented 7 years ago

Thanks for the really fast response!

The queue is already created and is durable. I wanted to use the queue to find out how many entries it has. Depending on that I would use a different consumer (standard/priority) ?

prolic commented 7 years ago

When you create a queue from the channel, it will not be created on Rabbitmq. Only a call to declareQueue will do that. So I suggest you create the queue instance like I described.

Am 03.04.2017 21:31 schrieb "Al3x Zamponi" notifications@github.com:

Thanks for the really fast response!

The queue is already created and is durable. I wanted to use the queue to find out how many entries it has. Depending on that I would use a different consumer (standard/priority) ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/prolic/HumusAmqp/issues/33#issuecomment-291143245, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYEvKKIchk77cgS4lca0IR_rx6CtqNDks5rsPSTgaJpZM4MxhN6 .

alexz707 commented 7 years ago

ok I understand, thanks! Do you know another way except declareQueue to get a count on the queue entries?

prolic commented 7 years ago

You can do an http call to Rabbitmq to get the info.

prolic commented 7 years ago

See https://github.com/richardfullmer/php-rabbitmq-management-api

alexz707 commented 7 years ago

Thanks a lot, will have a look at the mgmnt api :)

prolic commented 7 years ago

So can we close this issue now?

Am 03.04.2017 22:14 schrieb "Al3x Zamponi" notifications@github.com:

Thanks a lot, will have a look at the mgmnt api :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/prolic/HumusAmqp/issues/33#issuecomment-291155959, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYEvCvA1RWd4EM0ClIJugWIT2vhAPu4ks5rsP7LgaJpZM4MxhN6 .

alexz707 commented 7 years ago

Yes thanks a lot !