cody-greene / node-rabbitmq-client

RabbitMQ (0-9-1) client library with auto-reconnect & zero dependencies
MIT License
116 stars 8 forks source link

[Feature Request] Lazy Consumer #50

Closed Zeichen32 closed 4 months ago

Zeichen32 commented 4 months ago

It would be really helpful if Consumer could be create without starting consuming messages directly. In my usecase i want to inject the Consumer via a dependencies injection Container into a Service and want to start consuming messages after some other dependencies are ready.

I think maybe adding a lazy boalean flag to the Option could control if the connect method is called in the constructor.

I can work on a PR if you are open for such a feature.

cody-greene commented 4 months ago

Sure, go ahead. Something like:

interface ConsumerProps {
  /** If true, the consumer will not automatically start. You must call
   * consumer.start() yourself.
   * @default false */
  lazy?: boolean
}

class Consumer {
  /** When created with lazy=true, begin consuming. */
  start(): void {}
}

Should be simple enough.