initializeCompetingConsumer method

Future<void> initializeCompetingConsumer(
  1. String queueName,
  2. bool durable,
  3. String? consumerTag
)

This provides a producer-queue, competing consumer model.

The consumer subscribes to a queue together with other potential consumers while messages are distributed between them by the broker. Every message is processed by only one consumer.

RPC endpoints always use this model.

Implementation

Future<void> initializeCompetingConsumer(
    String queueName, bool durable, String? consumerTag) async {
  final channel = await _brokerService.openChannel();
  _channels.add(channel);
  final queue =
      await channel.queue(queueName, durable: durable, autoDelete: false);
  final consumer =
      await queue.consume(consumerTag: consumerTag, noAck: false);
  consumer.listen(_onData);
}