private async Task Subscribe(string productStream, string queryGroup) { try { await _connection.CreatePersistentSubscriptionAsync(productStream, queryGroup, PersistentSubscriptionSettings.Create().ResolveLinkTos().StartFromBeginning(), new UserCredentials(_eventStoreSettings.UserName, _eventStoreSettings.Password)); } catch (Exception e) { } async Task EventAppeared(EventStorePersistentSubscriptionBase s, ResolvedEvent e) { using (var scope = _serviceProvider.CreateScope()) { var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); var @event = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(e.Event.Data), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }) as INotification; await mediator.Publish(@event); } }; void SubscriptionDropped(EventStorePersistentSubscriptionBase e, SubscriptionDropReason s, Exception exc) { _subscriptions.TryTake(out e); _subscriptions.Add(_connection.ConnectToPersistentSubscriptionAsync(productStream, queryGroup, EventAppeared, SubscriptionDropped).Result); }; _subscriptions.Add(await _connection.ConnectToPersistentSubscriptionAsync(productStream, queryGroup, EventAppeared, SubscriptionDropped)); }
private async Task CreateSubscription(IEventStoreConnection connection, string stream, string group) { var persistentSubscriptionSettings = PersistentSubscriptionSettings.Create().DoNotResolveLinkTos().StartFromCurrent(); var userCredentials = new UserCredentials("admin", "changeit"); await connection.CreatePersistentSubscriptionAsync(stream, group, persistentSubscriptionSettings, userCredentials); }
public async Task Subscribe(string streamName, Func <Guid, object, Task> messageSender) { await DefaultRetryAsync(() => SubscribeImpl()); async Task SubscribeImpl() { await CreateSubscription(); await _conn.ConnectToPersistentSubscriptionAsync( streamName, _options.GroupSubscription, (_, x) => messageSender( GetAggregateId(x.Event.EventStreamId), _eventDeserializer.Deserialize(x.Event))); Guid GetAggregateId(string streamId) { var streamIdParts = streamId.Split('-'); return(streamIdParts.Length == 2 ? Guid.TryParse(streamIdParts[1], out Guid aggregateId) ? aggregateId : Guid.Empty : Guid.Empty); } async Task CreateSubscription() { var settings = PersistentSubscriptionSettings.Create() .ResolveLinkTos() .StartFromCurrent(); await _conn.CreatePersistentSubscriptionAsync(streamName, _options.GroupSubscription, settings, _options.Credentials); } } }
public async Task Crate() { #region CreatePersistentSubscription var userCredentials = new UserCredentials("admin", "changeit"); var settings = PersistentSubscriptionSettings .Create() .DoNotResolveLinkTos() .StartFromCurrent(); await conn.CreatePersistentSubscriptionAsync( "myStream", "grour1", settings, userCredentials ); var subscription = await conn.ConnectToPersistentSubscriptionAsync( "myStream", "group1", (_, evt) => Console.WriteLine($"Received: {Encoding.UTF8.GetString(evt.Event.Data)}") ); #endregion CreatePersistentSubscription }
public static async Task <int> Main(string[] args) { // enumerate all streams IEventStoreConnection conn = EventStoreConnection.Create(connection); await Task.Run(() => conn.ConnectAsync()); try { await conn.CreatePersistentSubscriptionAsync(stream, group, PersistentSubscriptionSettings.Create(), null); } catch { } dynamic ps = conn.ConnectToPersistentSubscription(stream, group, (s, e) => Process(s, e), (s, r, ex) => HandleException(s, r, ex), null, 2, false); Console.ReadKey(); }
private void CreateStream() { var settings = PersistentSubscriptionSettings.Create(); _connectionES.CreatePersistentSubscriptionAsync(streamName, "PictureScan", settings, _connectionES.Settings.DefaultUserCredentials); SetPermisions(); }
public override async Task <CreatePersistentSubscriptionResponse> CreatePersistentSubscription( CreatePersistentSubscriptionRequest request, ServerCallContext context) { await _eventStoreConnection.CreatePersistentSubscriptionAsync(request.Stream, request.GroupName, request.Settings.ToPersistentSubscriptionSettings(), request.UserCredentials.ToUserCredentials()); return(new CreatePersistentSubscriptionResponse()); }
private static async Task CreateSubscription(IEventStoreConnection conn, EventStoreOptions options) { var settings = PersistentSubscriptionSettings.Create() .ResolveLinkTos() .StartFromCurrent(); await conn.CreatePersistentSubscriptionAsync(options.Subscription.stream, options.Subscription.group, settings, options.Credentials); }
private async Task CreateSubscription(string subscription, string eventTypeStream, PersistentSubscriptionSettingsBuilder settings) { try { await _conn.CreatePersistentSubscriptionAsync(eventTypeStream, subscription, settings, _credentials); } catch { // Already exists } }
private static async Task StartMultipleSubscriptions() { try { await _subscriptionConnection.CreatePersistentSubscriptionAsync( "$et-AccountCreated", "InvoiceGeneration", PersistentSubscriptionSettings .Create() .StartFromBeginning() .CheckPointAfter(TimeSpan.FromSeconds(5)) .ResolveLinkTos() .Build(), new UserCredentials("admin", "changeit")); } catch (Exception e) { Console.WriteLine($"Subscription already exist."); } await _subscriptionConnection.ConnectToPersistentSubscriptionAsync("$et-AccountCreated", "InvoiceGeneration", AccountCreatedEventAppeared); }
private static void CreatePersistentSubscription(IEventStoreConnection conn) { try { conn.CreatePersistentSubscriptionAsync(StreamName, GroupName, PersistentSubscriptionSettings.Create().StartFromBeginning(), new UserCredentials("admin", "changeit")).Wait(); } catch (Exception e) { // Already exist } }
/// <summary> /// Creates the persistent connection. /// </summary> /// <param name="streamName">Name of the stream.</param> /// <param name="groupName">Name of the group.</param> /// <param name="persistentSubscriptionSettings">The persistent subscription settings.</param> /// <returns></returns> private async Task CreatePersistentSubscription(String streamName, String groupName, PersistentSubscriptionSettings persistentSubscriptionSettings) { Guard.ThrowIfNullOrEmpty(streamName, typeof(ArgumentNullException), "Stream Name cannot be null or empty when creating a Persistent Subscription"); Guard.ThrowIfNullOrEmpty(groupName, typeof(ArgumentNullException), "Group Name cannot be null or empty when creating a Persistent Subscription"); Guard.ThrowIfNull(persistentSubscriptionSettings, typeof(ArgumentNullException), "Persistent Subscription Settings cannot be null when creating a Persistent Subscription"); // Get the connection IEventStoreConnection connection = await this.GetEventStoreConnection(); // Attempt to create the subscription await connection.CreatePersistentSubscriptionAsync(streamName, groupName, persistentSubscriptionSettings, this.UserCredentials); }
public static void Method() { var userCredentials = new UserCredentials("admin", "changeit"); var settings = PersistentSubscriptionSettings.Create() .DoNotResolveLinkTos().StartFromCurrent(); conn.CreatePersistentSubscriptionAsync("newstream", "gr1", settings, userCredentials).Wait(); var subscription = conn.ConnectToPersistentSubscriptionAsync( "newstream", "gr1", (_, evt) => { Console.WriteLine("Received: " + Encoding.UTF8.GetString(evt.Event.Data)); }).Result; }
protected override void Given() { _conn = EventStoreConnection.Create(_node.TcpEndPoint); _conn.ConnectAsync().Wait(); _conn.CreatePersistentSubscriptionAsync(_streamName, _groupName, _settings, DefaultData.AdminCredentials).Wait(); _sub1 = _conn.ConnectToPersistentSubscription(_streamName, _groupName, (subscription, @event) => Console.WriteLine(), (subscription, reason, arg3) => Console.WriteLine()); _sub2 = _conn.ConnectToPersistentSubscription(_streamName, _groupName, (subscription, @event) => Console.WriteLine(), (subscription, reason, arg3) => Console.WriteLine(), DefaultData.AdminCredentials); }
private async Task EnsureSubscriptionExists(string queue, IEventStoreConnection connection) { try { await connection.CreatePersistentSubscriptionAsync(queue, queue, PersistentSubscriptionSettings.Create(), null).ConfigureAwait(false); } catch (Exception ex) { if (ex.Message != string.Format("Subscription group {0} on stream {0} already exists", queue)) { throw; } } }
public async Task Subscribe(CancellationToken cancelToken) { var stream = $"{_endpoint}.{Assembly.GetEntryAssembly().GetName().Version}"; var group = $"{_endpoint}.{Assembly.GetEntryAssembly().GetName().Version}.sub"; Logger.Write(LogLevel.Info, () => $"Endpoint [{_endpoint}] connecting to subscription group [{stream}]"); try { var settings = PersistentSubscriptionSettings.Create() .StartFromBeginning() .WithReadBatchOf(_readsize) .WithMessageTimeoutOf(TimeSpan.FromSeconds(60)) .CheckPointAfter(TimeSpan.FromSeconds(10)) .ResolveLinkTos() .WithNamedConsumerStrategy(SystemConsumerStrategies.RoundRobin); await _connection.CreatePersistentSubscriptionAsync(stream, group, settings, _connection.Settings.DefaultUserCredentials).ConfigureAwait(false); } catch (InvalidOperationException) { } ThreadPool.QueueUserWorkItem(_ => { while (Bus.OnMessage == null || Bus.OnError == null) { Logger.Warn($"Could not find NSBs onMessage handler yet - if this persists there is a problem."); Thread.Sleep(1000); } // PushSettings will only exist AFTER finding OnMessage if (_concurrencyLimit == null) { _concurrencyLimit = new SemaphoreSlim(Bus.PushSettings.MaxConcurrency); } _subscription = _connection.ConnectToPersistentSubscriptionAsync(stream, group, EventProcessor(cancelToken), subscriptionDropped: (sub, reason, e) => { Logger.Write(LogLevel.Warn, () => $"Subscription dropped for reason: {reason}. Exception: {e?.Message ?? "UNKNOWN"}"); ProcessingLive = false; Dropped?.Invoke(reason.ToString(), e); }, bufferSize: _readsize * 10, autoAck: false).Result; ProcessingLive = true; }); }
public async Task create(UserCredentials user) { try { var setting = create_subscription(); await event_store_connection.CreatePersistentSubscriptionAsync(Stream, Subscription, setting, user); } catch (Exception ex) { if (ex.GetType() != typeof(InvalidOperationException) || ex.Message != $"Subscription group {Subscription} on stream {Stream} already exists") { throw; } } }
public static void ConnectToPersistentSubscription( string chatRoom, string groupName, Action <ChatMessage> onRecieved) { Connection.CreatePersistentSubscriptionAsync( chatRoom, groupName, PersistentSubscriptionSettings.Create().StartFromBeginning().Build(), _userCredentials); Connection.ConnectToPersistentSubscription( groupName, chatRoom, OnRecievedPersistent(onRecieved)); }
private void CreateSubscription(IEventStoreConnection connection) { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create().StartFromCurrent(); try { connection.CreatePersistentSubscriptionAsync(_streamName, Group, settings, new UserCredentials("admin", "changeit")).Wait(); } catch (AggregateException ex) { if (ex.InnerException != null && (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {Group} on stream {_streamName} already exists")) { Console.WriteLine("Persistant Subscription: CreateSubscription exception :" + ex); throw; } } }
private void CreateSubscription() { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create() .StartFromCurrent(); try { conn.CreatePersistentSubscriptionAsync(this.settings.Stream, this.settings.SubscriptionGroup, settings, User).Wait(); } catch (AggregateException ex) { if (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {this.settings.SubscriptionGroup} on stream {this.settings.Stream} already exists") { throw; } } }
private void CreateSubscription() { var settings = PersistentSubscriptionSettings.Create() .DoNotResolveLinkTos() .StartFromCurrent(); try { conn.CreatePersistentSubscriptionAsync(streamName, groupName, settings, userCredentials).Wait(); } catch (Exception e) { if (e.InnerException?.GetType() != typeof(InvalidOperationException) && e.InnerException?.Message != $"Subscription group {groupName} on stream {streamName} already exists") { throw; } } }
private static void CreateSubscription(IEventStoreConnection conn) { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create() .DoNotResolveLinkTos() .StartFromCurrent(); try { conn.CreatePersistentSubscriptionAsync(STREAM, GROUP, settings, new UserCredentials("admin", "changeit")).Wait(); } catch (AggregateException ex) { if (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {GROUP} on stream {STREAM} already exists") { throw; } } }
private async Task CreatePersistenSubscription() { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create() .ResolveLinkTos() .StartFromBeginning() .WithExtraStatistics(); try { await _conn.CreatePersistentSubscriptionAsync(_streamName, "transactionReadModelWriter", settings, _adminCredentials); Console.WriteLine("PersistentSubscription created"); } catch (Exception e) { Console.WriteLine("PersistentSubscription already exists, using existing one."); } }
private static async Task CreateSubscription(IEventStoreConnection conn, EventStoreOptions options) { try { var settings = PersistentSubscriptionSettings.Create() .ResolveLinkTos() .StartFromCurrent(); await conn.CreatePersistentSubscriptionAsync(options.Subscription.stream, options.Subscription.group, settings, options.Credentials); } catch (AggregateException ex) { if (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {options.Subscription.group} on stream {options.Subscription.stream} already exists") { throw; } } }
/* * Normally the creating of the subscription group is not done in your general executable code. * Instead it is normally done as a step during an install or as an admin task when setting * things up. You should assume the subscription exists in your code. */ private void CreateSubscription() { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create() .DoNotResolveLinkTos() .StartFromCurrent(); try { _conn.CreatePersistentSubscriptionAsync(STREAM, GROUP, settings, User).Wait(); } catch (AggregateException ex) { if (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {GROUP} on stream {STREAM} already exists") { throw; } } }
public EventStoreDataFactory(string connectionString, string username, string password) { this.Username = username; this.Password = password; connection = EventStoreConnection.Create(connectionString); //EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)); // Don't forget to tell the connection to connect! connection.ConnectAsync().Wait(); //Should be run ONLY once actually. try { EventStore.ClientAPI.SystemData.UserCredentials credentials = new EventStore.ClientAPI.SystemData.UserCredentials(username, password); PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create().DoNotResolveLinkTos().StartFromCurrent(); connection.CreatePersistentSubscriptionAsync("fingrid.messaging.smsrequest", "fingrid.messaging.smsrequest.group", settings, credentials).Wait(); } catch { } }
public static async Task <bool> CreateSubscription( this IEventStoreConnection conn, string stream, string group, UserCredentials credentials, Microsoft.Extensions.Logging.ILogger logger, bool startFromCurrent = false) { try { var settings = (startFromCurrent) ? PersistentSubscriptionSettings .Create() .ResolveLinkTos() .StartFromCurrent() .Build() : PersistentSubscriptionSettings .Create() .ResolveLinkTos() .StartFromBeginning() .Build(); await conn.CreatePersistentSubscriptionAsync(stream, group, settings, credentials); return(true); } catch (InvalidOperationException invalidOperationException) { if (invalidOperationException.Message == $"Subscription group {group} on stream {stream} already exists") { return(true); } logger.LogError(invalidOperationException, invalidOperationException.Message); throw; } catch (Exception e) { logger.LogError(e, e.Message); throw; } }
public async Task InitializeActivityStream() { Logger.LogInformation("Initialize"); await DeleteActivitliesStream(); var conf = PersistentSubscriptionSettings .Create() .StartFromBeginning() .ResolveLinkTos() .CheckPointAfter(TimeSpan.FromSeconds(1)) .MinimumCheckPointCountOf(1) .MaximumCheckPointCountOf(10) .Build(); await conn.CreatePersistentSubscriptionAsync(Constants.StreamNameActivities, Constants.GroupNameActivities, conf, creds); }
public async Task InstallConsumerGroupFor(string stream, Func <PersistentSubscriptionSettingsBuilder, PersistentSubscriptionSettingsBuilder> alterSettings = null) { var settings = PersistentSubscriptionSettings.Create().PreferRoundRobin().ResolveLinkTos(); alterSettings = alterSettings ?? (x => x); settings = alterSettings(settings); var subscriberSettings = _environment.GetSettings <SubscribersSettings>(); var groupName = subscriberSettings.GetPersistentSubscriptionGroupNameFor(stream, _environment); try { await _eventStoreConnection.CreatePersistentSubscriptionAsync(stream, groupName, settings, _eventStoreConnectionString.GetUserCredentials()).ConfigureAwait(false); } catch (Exception ex) { _environment.Log(ex, "Failed to create consumer group for stream: {0}", LogLevel.Error, stream); } }
private void CreateSubscription(Projection projection) { PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create() .DoNotResolveLinkTos() .StartFromBeginning(); try { Console.WriteLine($"Persistent subscriptişng is creating for {projection}"); eventStoreConnection.CreatePersistentSubscriptionAsync(projection.ToString(), Group, settings, userCredentials).Wait(); } catch (AggregateException ex) { if (ex.InnerException.GetType() != typeof(InvalidOperationException) && ex.InnerException?.Message != $"Subscription group {Group} on stream {projection.ToString()} already exists") { throw; } } }
protected override void Given() { _conn = EventStoreConnection.Create(_node.TcpEndPoint.ToESTcpUri()); _conn.ConnectAsync().Wait(); _conn.CreatePersistentSubscriptionAsync(_streamName, _groupName, _settings, DefaultData.AdminCredentials).Wait(); _sub1 = _conn.ConnectToPersistentSubscription(_streamName,_groupName, (subscription, @event) => Console.WriteLine(), (subscription, reason, arg3) => Console.WriteLine()); _sub2 = _conn.ConnectToPersistentSubscription(_streamName, _groupName, (subscription, @event) => Console.WriteLine(), (subscription, reason, arg3) => Console.WriteLine(), DefaultData.AdminCredentials); }