async Task PublishBatch(IList <BatchPublish> batch) { try { var publishTag = _model.NextPublishSeqNo; if (batch.Count == 1) { var publish = batch[0]; _confirmations?.Add(publishTag, publish); publish.BasicPublish(_model, publishTag); } else { var publishBatch = _model.CreateBasicPublishBatch(); for (int i = 0; i < batch.Count; i++) { var publish = batch[i]; publish.Append(publishBatch, publishTag); _confirmations?.Add(publishTag++, publish); } publishBatch.Publish(); for (int i = 0; i < batch.Count; i++) { batch[i].Published(); } } } catch (Exception exception) { for (int i = 0; i < batch.Count; i++) { var publish = batch[i]; _confirmations?.Faulted(publish); publish.NotConfirmed(exception.Message); } } }
public Task Publish(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body, bool awaitAck) { return(_executor.Run(() => { var publishTag = _model.NextPublishSeqNo; var published = _confirmations?.Add(exchange, publishTag, basicProperties); try { _model.BasicPublish(exchange, routingKey, mandatory, basicProperties, body); } catch (Exception) { _confirmations?.Faulted(published); throw; } return awaitAck && published != null ? published.Confirmed : Task.CompletedTask; })); }