publish<T> method

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

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.declareExchange(exchange, BrokerExchangeType.topic))
        .then((ex) => ex.publish(
            utf8.encode(jsonEncode(encoded)).asUint8List(), topic));
  } catch (e, stack) {
    _publishChannel.invalidate();
    _log.warn('Amqp channel error, reconnecting.', error: e, trace: stack);
    await _publishChannel
        .get()
        .then((c) => c.declareExchange(exchange, BrokerExchangeType.topic))
        .then((ex) => ex.publish(
            utf8.encode(jsonEncode(encoded)).asUint8List(), topic));
  }
}