public async Task MergeIndexesAsync( UserCredentials?userCredentials = null, CancellationToken cancellationToken = default) { await new Operations.Operations.OperationsClient( await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).MergeIndexesAsync(EmptyResult, EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken)); }
public async Task <PersistentSubscription> SubscribeAsync(string streamName, string groupName, Func <PersistentSubscription, ResolvedEvent, int?, CancellationToken, Task> eventAppeared, Action <PersistentSubscription, SubscriptionDroppedReason, Exception?>?subscriptionDropped = null, UserCredentials?userCredentials = null, int bufferSize = 10, bool autoAck = true, CancellationToken cancellationToken = default) { if (streamName == null) { throw new ArgumentNullException(nameof(streamName)); } if (groupName == null) { throw new ArgumentNullException(nameof(groupName)); } if (eventAppeared == null) { throw new ArgumentNullException(nameof(eventAppeared)); } if (streamName == string.Empty) { throw new ArgumentException($"{nameof(streamName)} may not be empty.", nameof(streamName)); } if (groupName == string.Empty) { throw new ArgumentException($"{nameof(groupName)} may not be empty.", nameof(groupName)); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize)); } var operationOptions = Settings.OperationOptions.Clone(); operationOptions.TimeoutAfter = new TimeSpan?(); var call = new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient( await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).Read(EventStoreCallOptions.Create( Settings, operationOptions, userCredentials, cancellationToken)); return(await PersistentSubscription.Confirm(call, new ReadReq.Types.Options { BufferSize = bufferSize, GroupName = groupName, StreamIdentifier = streamName, UuidOption = new ReadReq.Types.Options.Types.UUIDOption { Structured = new Empty() } }, autoAck, eventAppeared, subscriptionDropped ?? delegate { }, cancellationToken).ConfigureAwait(false)); }
public async Task RestartSubsystemAsync(UserCredentials?userCredentials = null, CancellationToken cancellationToken = default) { await _client.RestartSubsystemAsync(new Empty(), EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken)); }
private async Task <IWriteResult> AppendToStreamInternal( AppendReq header, IEnumerable <EventData> eventData, EventStoreClientOperationOptions operationOptions, UserCredentials?userCredentials, CancellationToken cancellationToken) { using var call = _client.Append(EventStoreCallOptions.Create(Settings, operationOptions, userCredentials, cancellationToken)); IWriteResult writeResult; try { await call.RequestStream.WriteAsync(header).ConfigureAwait(false); foreach (var e in eventData) { _log.LogTrace("Appending event to stream - {streamName}@{eventId} {eventType}.", header.Options.StreamIdentifier, e.EventId, e.Type); await call.RequestStream.WriteAsync(new AppendReq { ProposedMessage = new AppendReq.Types.ProposedMessage { Id = e.EventId.ToDto(), Data = ByteString.CopyFrom(e.Data.Span), CustomMetadata = ByteString.CopyFrom(e.Metadata.Span), Metadata = { { Constants.Metadata.Type, e.Type }, { Constants.Metadata.ContentType, e.ContentType } } } }).ConfigureAwait(false); } await call.RequestStream.CompleteAsync().ConfigureAwait(false); } finally { var response = await call.ResponseAsync.ConfigureAwait(false); if (response.Success != null) { writeResult = new SuccessResult(response.Success.CurrentRevisionOptionCase == AppendResp.Types.Success.CurrentRevisionOptionOneofCase.NoStream ? StreamRevision.None : new StreamRevision(response.Success.CurrentRevision), response.Success.PositionOptionCase == AppendResp.Types.Success.PositionOptionOneofCase.Position ? new Position(response.Success.Position.CommitPosition, response.Success.Position.PreparePosition) : default); _log.LogDebug("Append to stream succeeded - {streamName}@{logPosition}/{nextExpectedVersion}.", header.Options.StreamIdentifier, writeResult.LogPosition, writeResult.NextExpectedStreamRevision); } else { if (response.WrongExpectedVersion != null) { var actualStreamRevision = response.WrongExpectedVersion.CurrentRevisionOptionCase switch { AppendResp.Types.WrongExpectedVersion.CurrentRevisionOptionOneofCase.CurrentNoStream => StreamRevision.None, _ => new StreamRevision(response.WrongExpectedVersion.CurrentRevision) }; _log.LogDebug( "Append to stream failed with Wrong Expected Version - {streamName}/{expectedRevision}/{currentRevision}", header.Options.StreamIdentifier, new StreamRevision(header.Options.Revision), actualStreamRevision); if (operationOptions.ThrowOnAppendFailure) { if (response.WrongExpectedVersion.ExpectedRevisionOptionCase == AppendResp.Types .WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedRevision) { throw new WrongExpectedVersionException(header.Options.StreamIdentifier, new StreamRevision(response.WrongExpectedVersion.ExpectedRevision), actualStreamRevision); } var expectedStreamState = response.WrongExpectedVersion.ExpectedRevisionOptionCase switch { AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedAny => StreamState.Any, AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedNoStream => StreamState.NoStream, AppendResp.Types.WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedStreamExists => StreamState.StreamExists, _ => throw new InvalidOperationException() }; throw new WrongExpectedVersionException(header.Options.StreamIdentifier, expectedStreamState, actualStreamRevision); } if (response.WrongExpectedVersion.ExpectedRevisionOptionCase == AppendResp.Types .WrongExpectedVersion.ExpectedRevisionOptionOneofCase.ExpectedRevision) { writeResult = new WrongExpectedVersionResult(header.Options.StreamIdentifier, new StreamRevision(response.WrongExpectedVersion.ExpectedRevision), actualStreamRevision); } else { writeResult = new WrongExpectedVersionResult(header.Options.StreamIdentifier, StreamRevision.None, actualStreamRevision); } } else { throw new InvalidOperationException("The operation completed with an unexpected result."); } } } return(writeResult); } } }
public async Task RestartSubsystemAsync(UserCredentials?userCredentials = null, CancellationToken cancellationToken = default) { await new Projections.Projections.ProjectionsClient( await SelectCallInvoker(cancellationToken).ConfigureAwait(false)).RestartSubsystemAsync(new Empty(), EventStoreCallOptions.Create(Settings, Settings.OperationOptions, userCredentials, cancellationToken)); }