Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

restinio and amqp-cpp #13

Open jm130794 opened 5 years ago

jm130794 commented 5 years ago

Hello, I am asked if it is possible to use amqp-cpp with restinio. As I don't know, I ask the question to the developers of restinio:)

Do you think this is possible easily enough?

Jean-Marc

eao197 commented 5 years ago

Hi!

Do you want to use the same event-loop for amqp-cpp and RESTinio?

ngrodzitski commented 5 years ago

Hi Jean-Marc,

I've taken a look on amqp-cpp, and I'm pretty sure restinio and amqp-cpp can coexist in a single application. Even though boost-asio is not manifested as officially supported you have the following options:

  1. Use different event-loop engines (a simple way: run separate threads for amqp-loop and restinio-loop, a hard way: you still can leverage a single thread if you really need it).
  2. Anyway use an existing boost-asio wrapper and run restinio on the same io_context.

PS Depending on how complicated your internal logic is (seems like you want to be very async) it might worth an effort to look at Actor model and apply it to your case. For example, we've used our own amqp-client (back in 2014) with SObjectizer (a library implementing actor model in C++) in production, so I can say that amqp+sobjectizer works nicely.

jm130794 commented 5 years ago

I have never used SObjectizer but indeed, your slides are very interesting. I'm going to test this library.

eao197 commented 5 years ago

I don't expect any serious problem if:

May be if you tell some more details about your task and desired application design we could make more useful advices.

jm130794 commented 5 years ago

Hi, I started studying SObjectizer. It seems to me that I have a good understanding of how agents and associated mboxes work. I have made one or two programs and everything is working well.

I have a question: if I integrate AMQP-CPP into an agent (maybe I'm wrong), will the agent be able to handle the events to which it has subscribed? Isn't the ev_loop loop blocking?

Jean-Marc

eao197 commented 5 years ago

if I integrate AMQP-CPP into an agent (maybe I'm wrong), will the agent be able to handle the events to which it has subscribed? Isn't the ev_loop loop blocking?

If I understand you correctly you want to run AMQP-CPP (with underlying ev_loop) in so_evt_start() of some agent. Right?

In that case, I think, ev_loop will block the work thread of that agent and agent can't handle messages. Maybe it is possible to write a special dispatcher that will use ev_loop from AMQP-CPP to dispatch events for agents bound to that dispatcher (like we do in so_5_extra for Aiso: asio_thread_pool). But it is a complex task.

If you can spawn several wok threads in your app then, I think, the easiest way can be:

There are no problems with RESTinio -- it's an asynchronous framework that allows delegating of actual request processing to separate worker thread. Unfortunately, I don't know does AMQP-CPP allow this.