publish<T> method
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));
}
}