publish<T> method

Future<void> publish<T>(
  1. String topic,
  2. T event
)

Implementation

Future<void> publish<T>(String topic, T event) async {
  final encoded =
      (event is TransferObjectBase) ? event.toJson() : encodeTyped<T>(event);

  try {
    await _publishChannel
        .get()
        .then((c) => c.exchange(exchange, ExchangeType.TOPIC))
        .then((ex) => ex.publish(encoded, topic));
  } catch (e, stack) {
    _publishChannel.invalidate();
    _log.warn('Amqp channel error, reconnecting.', error: e, trace: stack);
    await _publishChannel
        .get()
        .then((c) => c.exchange(exchange, ExchangeType.TOPIC))
        .then((ex) => ex.publish(encoded, topic));
  }
}