dart_amqp icon indicating copy to clipboard operation
dart_amqp copied to clipboard

HELP: executing messages only one time

Open moinologics opened this issue 1 year ago • 2 comments

i want to perform a simple task

run consumer in background for a queue, and pick 5 messages at a time and perform operation on each. how to achieve this?

moinologics avatar Aug 07 '23 19:08 moinologics

It sounds like you want to configure a per-consumer pre-fetch count of 5.

You can start with the receiver example here and specify an appropriate QoS) for your use case. For example:

channel.qos(prefetch_count=5)

You can find out more about prefetching works here.

achilleasa avatar Aug 08 '23 05:08 achilleasa

i have tried this example as it's working as expected. but i want to use something like this in flutter.

i have a function in main.dart file in flutter app, thats runs on a button click

Future<void> consumeQueue() async {
  final amqpClient = amqp.Client(settings: connectionSettings); //
  final channel = await amqpClient.channel();
  final queue = await channel.queue(settings['amqp_queue']);
  amqpConsumer = await queue.consume(); // amqpConsumer is global var as need to call cancel() method from somewhere else
  final subscription = amqpConsumer?.listen(handleIncomingSMSRequest);
}

i want to keep consumer listen in background, but consumer is consuming messages one time and after not receiving any message.

moinologics avatar Aug 09 '23 17:08 moinologics