achilleasa / dart_amqp

Dart AMQP client implementing protocol version 0.9.1
MIT License
79 stars 40 forks source link

HELP: executing messages only one time #101

Open moinologics opened 1 year ago

moinologics commented 1 year ago

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?

achilleasa commented 1 year ago

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.

moinologics commented 1 year ago

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.