stomp icon indicating copy to clipboard operation
stomp copied to clipboard

RabbitMq support

Open dbalabka opened this issue 8 years ago • 17 comments
trafficstars

Hello, I'm looking for possibility to apply amphp in existing projects. Is there any plan to support RabbitMq or implement it in separete library?

dbalabka avatar Feb 27 '17 19:02 dbalabka

Hi, I don't have any plans to implement the AMQP protocol at this time just because it's 100+ pages of specification ... really a terrible thing to have to implement.

That being said, I implemented this STOMP library specifically so I could enable the RabbitMQ stomp plugin and use it with rabbit at my company. Just follow the instructions for enabling the stomp plugin and you should be able to use this library with Rabbit just fine.

Let me know if you have specific questions about how to interface with an existing RabbitMQ server.

rdlowrey avatar Feb 27 '17 19:02 rdlowrey

Personally I'm going to use bunny. It's based on ReactPHP instead of Amphp but since Amphp accepts React promises it should work just fine.

enumag avatar Sep 10 '19 14:09 enumag

@enumag you can receive some strange bugs using Bunny with AMPHP. May be, I can suggest you my implementation of AMQP at top of AMPHP?

zloyuser avatar Sep 10 '19 15:09 zloyuser

@zloyuser Can you be more specific on what bugs can occur with bunny? I didn't know your library and now I'm of course considering it. But still bunny is used by lot more people and therefore less likely to die in a year or two so I'd still choose bunny if there was no disadvantage.

enumag avatar Sep 10 '19 21:09 enumag

@zloyuser I too am curious what issues you'd have with bunny and Amp. Maybe there's a bug that needs to be addressed? Very cool that you made a library using Amp for AMQP, I was not aware of it!

I'm not really sure what the plan is for this library… @rdlowrey started it, but no one else on the project uses stomp. It may be best to archive it and point people toward @zloyuser's library.

trowski avatar Sep 11 '19 14:09 trowski

ping @zloyuser

enumag avatar Sep 21 '19 12:09 enumag

Sorry, I have too many work last weeks. @enumag, I cant reproduce bags with current version of amphp and bunny, but if you use bunny with amphp (or any other reactphp library) you need understand that you actually use two event loop, one inside another. This, probably, not a problem if you use same backend driver as libevent or libuv, but with stream select driver, that lead to performance degradation (because one more select syscall in loop).

zloyuser avatar Sep 25 '19 07:09 zloyuser

I'm not really sure what the plan is for this library… @rdlowrey started it, but no one else on the project uses stomp. It may be best to archive it and point people toward @zloyuser's library.

@trowski, I don't think that you need archive that library. STOMP and AMQP are two different protocol, and STOMP may be used not only for rabbitmq.

zloyuser avatar Sep 25 '19 07:09 zloyuser

@zloyuser

if you use bunny with amphp (or any other reactphp library) you need understand that you actually use two event loop

I don't understand. Why would there be a second event loop? Amphp does not use react event loop to resolve react promises. It just adapts the react promise to amp promise.

enumag avatar Sep 25 '19 08:09 enumag

Let look at adapt function. Amphp just wrap up ReactPHP promise and add callback to resolve Deferred on than method. But who will resolve original Promise? Obviously, ReactPHP event loop inside bunnyphp.

Too see what happens inside bunnyphp at this and that places.

zloyuser avatar Sep 25 '19 09:09 zloyuser

Ah yeah, you're right. That kinda sucks... Ok, I'll consider using your lib then.

enumag avatar Sep 25 '19 09:09 enumag

if you use bunny with amphp (or any other reactphp library) you need understand that you actually use two event loop, one inside another

@enumag @zloyuser This is incorrect. ReactAdapter implements React's LoopInterface by creating watchers in Amp's event loop. An application mixing Amp and React libraries uses only one event loop.

trowski avatar Sep 25 '19 14:09 trowski

yep, I agree. Сompletely forgot about ReactAdapter. If you manually create bunnyphp client with adapter, ofcourse it will share loop events:

<?php

use Amp\Loop;
use Amp\ReactAdapter\ReactAdapter;
use Bunny\Async\Client;

Loop::run(function () {
    $reactLoop = new ReactAdapter(Loop::get());
    $client = new Client($reactLoop, ...);
});

zloyuser avatar Sep 25 '19 15:09 zloyuser

Minor nit: ReactAdapter also has a static get() method.

<?php

use Amp\ReactAdapter\ReactAdapter;
use Bunny\Async\Client;

Loop::run(function () {
    $reactLoop = ReactAdapter::get();
    $client = new Client($reactLoop, ...);
});

trowski avatar Sep 25 '19 15:09 trowski

@trowski may be, will be helpful add that example to ReactPHP section in promise documentation and/or ReactAdapter repository?

Looks easy to forget provide proper adapter for ReactPHP libraries, because many of them rely on static LoopFactory::create method.

zloyuser avatar Sep 25 '19 15:09 zloyuser

Yes, documentation is lacking for several repos. I plan to focus on it soon after final tags of some repos we have with RC tags.

It's frustrating that React offers no chance to inject your own loop implementation into LoopFactory::create(). I could overwrite the class in the adaptor library so that it returns only the adaptor… hmm…

trowski avatar Sep 25 '19 15:09 trowski

There is a documentation for react adapter here. It just doesn't seem to be linked anywhere - not from the packages page nor from the promises section where the paragraph about react is. Maybe I can send a PR this weekend.

EDIT: Ah the adapter docs is actually linked at the very bottom of the packages page.

enumag avatar Sep 25 '19 18:09 enumag