subscribe method

Future<void> subscribe(
  1. MessageHandler handler, {
  2. List<MessageHandler> middlewares = const [],
})

Register a handler to subscribe to messages sent to the topic.

Implementation

Future<void> subscribe(MessageHandler handler,
    {List<MessageHandler> middlewares = const []}) async {
  var registrationRequest = $tp.RegistrationRequest(topicName: name);

  final composedHandler =
      composeMiddleware([...middlewares, handler], MessageContext.fromCtx);

  var worker = SubscriptionWorker(registrationRequest, composedHandler,
      client: _subscriberClient);

  await worker.start();
}