Hi, For certain reasons I can't paste code here, so I'll try to give a pseudo-code algorithm that worked for me with Proton-C. Don't know how much control you have with the Python client.
--- Step 1: init --- - Initialize proton/main event loop up to the moment you get the FLOW event --> yield ---- Step 2: program main loop ---- While(true) { Read from external If (nothing read) then { if (AMQP echo must be sent) then { amqp_send(echo_message) adjust the tracking of link credit resume proactor main event loop (proactor_done + proactor_wait) and handle events --> if FLOW event is seen then yield continue } } else if (message read) { amqp_send(message) adjust the tracking of link credit resume proactor main event loop (proactor_done + proactor_wait) and handle events --> if FLOW event is seen --> yield } } Others may have better ideas, I am just beggining to use Proton-C. Hope this helps, Adrian On Thu, Jul 16, 2020, 8:36 AM Francesco Raviglione < francescorav.es...@gmail.com> wrote: > Dear Adrian, > Thank you very much for your reply. > > I tried following your suggestion, by attempting to find a way to call an > external function reading the data from an external source, and returning > it when available. > > However, unfortunately, it seems to be slightly easier to control the > behaviour of the event loop in C than in Pyhton. > In particular, in Python, if I call any blocking function (even a > time.sleep(0.1), sleeping for just 100 ms) inside "on_sendable", the > messages are only buffered and never sent (do you know why? Is the > "on_sendable" handler supposed to be executed as fast as possible without > blocking to have the messages being sent immediately?). > If, instead, I just do not block and send the data only if available (for > instance by implementing a mechanism equivalent to a non-blocking read from > a pipe, with poll(), letting "on_sendable" finish without sending anything, > if there is no data available), only one "on_sendable" event is generated > and the event loop does not seem to return any other event which I could > use to send the data, which may be now available (for example, the > equivalent of C's PN_DELIVERY does not seem to exist). > > Do you know if there are other ways to solve this issue? > When you were "yielding" the control of the main loop to an external > function, was it blocking in some way, waiting for data to be available? > > Thank you very much, > Francesco > > > Il giorno mer 15 lug 2020 alle ore 18:40 Adrian Florea < > florea....@gmail.com> > ha scritto: > > > Hi Francesco, > > > > I achieved similar behavior but using Qpid Proton-C (AMQP send-only > > program). > > > > After initialiazing proton and getting the first FLOW event, I simply > > "yield" main event loop control to an external/looping function that can > > read from a different source and then send the same message to an AMQP > > destination. > > > > It may seem hard in the beggining but once you get a hold on how to > > integrate proton events loop into your program loop, it has good chances > to > > work. > > > > Adrian > > > > > > On Wed, Jul 15, 2020, 11:22 AM Francesco Raviglione < > > francescorav.es...@gmail.com> wrote: > > > > > Dear all, > > > I'm trying to use the Python version of Qpid Proton to send data to an > > AMQP > > > 1.0 broker. > > > I've seen that several examples are sending data which was > > > available/defined before the AMQP event loop is started. > > > However, I need to send data only when it becomes available from an > > > external process (for example by waiting for it on a Pipe, with > > > self.amqp_pipe_end.recv()), and then send it immediately to the broker. > > > If I try to wait on a pipe inside "on_sendable", no message is actually > > > transferred to the broker, as the event loop is "blocked" waiting for > new > > > data and cannot manage properly the AMQP 1.0 connection (is this > > correct?). > > > How could I achieve the desired result? How can I make the loop wait > for > > > external data and then immediately send it? > > > > > > Thank you very much in advance, > > > Francesco Raviglione > > > >