alanxz / rabbitmq-c

RabbitMQ C client
MIT License
1.74k stars 662 forks source link

Two instances of amqp_connection_state_t #529

Open mix911 opened 5 years ago

mix911 commented 5 years ago

Hello!

while(true)
{
  //
  // It blocks the thread if I understand right.
  //
  ret = amqp_consume_message(m_pConnection, &envelope, NULL, 0);
  //
  // Here we do something with envelope, it can take some significant time.
  //
  /*......*/
  //
  // Here we tell that message was delivered.
  //
  if (is_everething_fine)
    amqp_basic_ack(m_pConnection, 1, message.deliveryTag, false);
  else
    continue;
}

The point is, that if something went wrong during handling a message it won't be acknowledged, so we will have the second attempt on the next iteration. But the problem is that we have to spend some significant time on handling a message, so the thread will be unable to consume another message. I believe it is clear why handling a message in another thread isn't a solution, according to the library description it won't work, because "You cannot share a socket, an amqp_connection_state_t, or a channel between threads using librabbitmq."

Maybe there is some way to create two instances of amqp_connection_state_t, one for consumption and another one for acknowledging?

AgelessDick commented 5 years ago

Are you trying to receive a message, then spawn a task (creating a new thread), then acknowledge the message after the task is complete? It's what we're trying to achieve and it's not clear what is a correct way to do so.

Is it possible to have two amqp_connection_state_t objects and use them like this:

It would be nice to get some help, thanks!

mix911 commented 5 years ago

Are you trying to receive a message, then spawn a task (creating a new thread), then acknowledge the message after the task is complete? It's what we're trying to achieve and it's not clear what is a correct way to do so.

Is it possible to have two amqp_connection_state_t objects and use them like this:

  • Receive the message using the first connection, process it in another thread (without use of this connection).
  • Acknowledge the message using second connection (which exists in some other thread) using same delivery tag.

It would be nice to get some help, thanks!

Hi AgelessDick!

The idea seems witty, might be it will even work. But still the question is, does it correct to use two amqp_connection_state_t and use it in the way that was described? Will it work in the future? It's not clear from available documentation.

StanleyWm commented 4 years ago

Are you trying to receive a message, then spawn a task (creating a new thread), then acknowledge the message after the task is complete? It's what we're trying to achieve and it's not clear what is a correct way to do so.

Is it possible to have two amqp_connection_state_t objects and use them like this:

  • Receive the message using the first connection, process it in another thread (without use of this connection).
  • Acknowledge the message using second connection (which exists in some other thread) using same delivery tag.

It would be nice to get some help, thanks!

I have the same problem. Is your method effective?