private void CreateSubscription()
        {
            var settings = ConnectionSettings
                           .Create()
                           .KeepReconnecting()
                           .KeepRetrying()
                           //.EnableVerboseLogging()
                           .UseConsoleLogger();

            // PersistentSubscriptionSettings settings = PersistentSubscriptionSettings.Create()
            //     .DoNotResolveLinkTos()
            //     .StartFromCurrent();

            try
            {
                _eventStoreConnection.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User).Wait();
                // foreach (var ev in _subscriptionConfiguration.SubscribedEvents)
                // {
                //     _eventStoreConnection.SubscribeToStreamAsync(ev.Key ,false  , EventAppeared , SubscriptionDropped , User ).Wait();
                // }
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException != null && (ex.InnerException.GetType() != typeof(InvalidOperationException) &&
                                                  ex.InnerException?.Message !=
                                                  $"Subscription group on stream already exists"))
                {
                    //throw;
                }
            }
        }
Exemplo n.º 2
0
 private async void ConnectToSubscription()
 {
     try
     {
         _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User);
     }
     catch
     {
         _conn.ConnectAsync().Wait();
         _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User);
     }
 }
Exemplo n.º 3
0
        private async void ConnectToSubscription()
        {
            var bufferSize = 10;
            var autoAck    = true;

            try
            {
                _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User);
            }
            catch
            {
                _conn.ConnectAsync().Wait();
                _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User);
            }
        }
 protected void SubscribeToAll(string login, string password)
 {
     using (Connection.SubscribeToAllAsync(false, (x, y) => { }, (x, y, z) => { },
                                           login == null && password == null ? null : new UserCredentials(login, password)).Result)
     {
     }
 }
Exemplo n.º 5
0
        public async Task Load()
        {
            var readEvents = await _storeConnection.ReadAllEventsForwardAsync(new Position(0, 0), 4000, false);

            foreach (var resolvedEvent in readEvents.Events)
            {
                Console.WriteLine("Processing event", resolvedEvent.Event.EventType);
                ProcessEvent(resolvedEvent);
            }

            _storeConnection.SubscribeToAllAsync(false, EventAppeared);
        }
 /// <summary>
 /// Asynchronously subscribes to all events in the Event Store. New
 /// events written to the stream while the subscription is active
 /// will be pushed to the client.
 /// </summary>
 /// <param name="target">The connection to subscribe to</param>
 /// <param name="resolveLinkTos">Whether to resolve Link events automatically</param>
 /// <param name="eventAppeared">An action invoked when a new event is received over the subscription</param>
 /// <param name="subscriptionDropped">An action invoked if the subscription is dropped</param>
 /// <param name="userCredentials">User credentials to use for the operation</param>
 /// <returns>An <see cref="EventStoreSubscription"/> representing the subscription</returns>
 public static Task <EventStoreSubscription> SubscribeToAllAsync(
     this IEventStoreConnection target,
     bool resolveLinkTos,
     Action <EventStoreSubscription, ResolvedEvent> eventAppeared,
     Action <EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
     UserCredentials userCredentials = null) =>
 target.SubscribeToAllAsync(
     resolveLinkTos,
     ToTask(eventAppeared),
     subscriptionDropped,
     userCredentials
     );
 public async Task RegisterAsync(Type eventType)
 {
     if (_subscribedEventTypes.Contains(eventType))
     {
         return;
     }
     if (_subscription == null)
     {
         //TODO: lock etc?
         _subscription = await _connection.SubscribeToAllAsync(true, OnEventDelivered, OnSubscriptionDropped, new UserCredentials("admin", "changeit"));
     }
     _subscribedEventTypes.Add(eventType);
 }
Exemplo n.º 8
0
        private Task <EventStoreSubscription> SubscribeToAll()
        {
            //TODO: Before trying to resubscribe - how to ensure that store is active and ready to accept.
            //AN: EventStoreConnection automatically tries to connect (if not already connected) to EventStore,
            //so you don't have to do something manually
            //Though in case of errors, you need to do some actions (if EventStore server is down or not yet up, etc)
            var task = eventStoreConnection.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped);

            if (!task.Wait(ReconnectTimeoutMillisec))
            {
                throw new TimeoutException("ReconnectedAfterSubscriptionException");
            }
            return(Task.FromResult(task.GetAwaiter().GetResult()));

            //return await eventStoreConnection.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped);
        }
Exemplo n.º 9
0
        public Task Start()
        {
            if (_started)
            {
                return(Task.CompletedTask);
            }

            Log.Info("Starting realtime subscription for meta updates");
            _started = true;

            return(_connection.SubscribeToAllAsync(
                       false,
                       (_, re) => HandleEvent(re),
                       HandleDrop
                       ));
        }
Exemplo n.º 10
0
 private async Task <EventStoreSubscription> SubscribeToAllEvents(Action <IEvent> pumpEvent, Action <Exception> pumpError)
 {
     return(await _connection.SubscribeToAllAsync(
                true,
                (subscription, ev) =>
     {
         try
         {
             ProcessReceivedEvent(ev, pumpEvent);
         }
         catch (Exception ex)
         {
             pumpError(ex);
         }
     },
                (subscription, reason, ex) => OnSubscriptionDropped(reason, ex, pumpError, pumpEvent)));
 }
Exemplo n.º 11
0
        public async Task <ISubscription> SubscribeToAll(Func <ISubscription, IEventData, Task> onEventAppeared,
                                                         Action <ISubscription, string, Exception> onSubscriptionDropped = null,
                                                         IUserCredentials userCredentials = null)
        {
            var subscriptionId = Guid.NewGuid().ToString();
            var creds          = userCredentials != null
                ? new global::EventStore.ClientAPI.SystemData.UserCredentials(userCredentials.Username,
                                                                              userCredentials.Password)
                : null;
            var esSubscription = await _connection.SubscribeToAllAsync(true,
                                                                       async (_, ev) => await HandleEvent(onEventAppeared, _subscriptions[subscriptionId], ev),
                                                                       (_, reason, ex) => onSubscriptionDropped(_subscriptions[subscriptionId], reason.ToString(), ex),
                                                                       creds);

            var subscription = _subscriptions[subscriptionId] = new Subscription(esSubscription);

            return(subscription);
        }
        public async Task SubscribeToOrdersFromAll()
        {
            await _connection.SubscribeToAllAsync(false, (sub, evnt) =>
            {
                // Subscribe to OrderCompleted events and write to console
                Console.WriteLine($"Received Event {evnt.Event.EventNumber}@{evnt.Event.EventStreamId} - {evnt.Event.EventType}");
                if (evnt.Event.EventType == typeof(OrderCompleted).FullName)
                {
                    var @event = (OrderCompleted)Helper.ConstructEvent(evnt);
                    Console.WriteLine($"Received Order for {@event.UserId} {@event.CartId}");
                    Console.WriteLine();
                }
            },
                                                  (sub, reason, ex) => {
                Console.WriteLine($"Subscription dropped because {reason}. Exception: {ex}");
            }, _credentials);

            Console.WriteLine("Subscribed to all events");
        }
Exemplo n.º 13
0
 protected virtual void ListenForNotificationsOnConnection(IEventStoreConnection connection)
 {
     connection.SubscribeToAllAsync(true, DisplayNotificationArrival, DisplaySubscriptionDropped).RunSynchronously();
 }
Exemplo n.º 14
0
 protected async Task SubscribeToAll(string login, string password)
 {
     using (await Connection.SubscribeToAllAsync(false, (x, y) => Task.CompletedTask, (x, y, z) => { },
                                                 login == null && password == null ? null : new UserCredentials(login, password))) {
     }
 }
 public IDisposable Subscribe(IObserver <T> observer)
 {
     _observer     = observer;
     _subscription = _connection.SubscribeToAllAsync(_resolveLinkTos, EventAppeared, SubscriptionDropped).Result;
     return(Disposable.Create(Stop));
 }
Exemplo n.º 16
0
 public bool Start()
 {
     _connection.SubscribeToAllAsync(false, EventAppeared).Wait();
     Log.Info("AssociateAccount EndPoint started");
     return(true);
 }