private async Task <CommandSendReceipt> SendPackage(bool autoAssignSequenceId) { try { _cachedSendPackage.Metadata.PublishTime = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); if (autoAssignSequenceId) { _cachedSendPackage.Command.SequenceId = _sequenceId.Current; _cachedSendPackage.Metadata.SequenceId = _sequenceId.Current; } else { _cachedSendPackage.Command.SequenceId = _cachedSendPackage.Metadata.SequenceId; } var response = await _connection.Send(_cachedSendPackage); response.Expect(BaseCommand.Type.SendReceipt); if (autoAssignSequenceId) { _sequenceId.Increment(); } return(response.SendReceipt); } finally { if (autoAssignSequenceId) { _cachedSendPackage.Metadata.SequenceId = 0; // Reset in case the user reuse the MessageMetadata, but is not explicitly setting the sequenceId } } }
private async Task <CommandSendReceipt> SendPackage( MessageMetadata metadata, ReadOnlySequence <byte> payload, bool autoAssignSequenceId, CancellationToken cancellationToken) { var sendPackage = _sendPackagePool.Get(); if (sendPackage.Command is null) { sendPackage.Command = new CommandSend { ProducerId = _id, NumMessages = 1 }; } sendPackage.Metadata = metadata; sendPackage.Payload = payload; try { metadata.PublishTime = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); if (autoAssignSequenceId) { sendPackage.Command.SequenceId = _sequenceId.Current; sendPackage.Metadata.SequenceId = _sequenceId.Current; } else { sendPackage.Command.SequenceId = sendPackage.Metadata.SequenceId; } var response = await _connection.Send(sendPackage, cancellationToken).ConfigureAwait(false); response.Expect(BaseCommand.Type.SendReceipt); if (autoAssignSequenceId) { _sequenceId.Increment(); } return(response.SendReceipt); } finally { // Reset in case the user reuse the MessageMetadata, but is not explicitly setting the sequenceId if (autoAssignSequenceId) { sendPackage.Metadata.SequenceId = 0; } _sendPackagePool.Return(sendPackage); } }
private async Task <CommandSendReceipt> SendPackage(bool autoAssignSequenceId) { try { _cachedSendPackage.Metadata.PublishTime = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); if (autoAssignSequenceId) { _cachedSendPackage.Command.SequenceId = _sequenceId.Current; _cachedSendPackage.Metadata.SequenceId = _sequenceId.Current; } else { _cachedSendPackage.Command.SequenceId = _cachedSendPackage.Metadata.SequenceId; } var response = await _connection.Send(_cachedSendPackage); response.Expect(BaseCommand.Type.SendReceipt); if (autoAssignSequenceId) { _sequenceId.Increment(); } return(response.SendReceipt); } catch (Exception exception) { if (_faultStrategy.DetermineFaultAction(exception) == FaultAction.Relookup) { _proxy.Disconnected(); } throw; } finally { if (autoAssignSequenceId) { _cachedSendPackage.Metadata.SequenceId = 0; // Reset in case the user reuse the MessageMetadata, but is not explicitly setting the sequenceId } } }