Exemplo n.º 1
0
 public static EventStoreSubscription GetLiveOnlyEventStoreSubscription(
     this IEventStoreConnection eventStoreConnection,
     Type typeofDomainObject,
     Action <EventStoreSubscription, ResolvedEvent> eventAppeared,
     Action <EventStoreSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
     UserCredentials userCredentials = null,
     bool resolveLinkTos             = true,
     Guid aggregateId = default(Guid))
 {
     try
     {
         var streamName = typeofDomainObject.GetStreamNameBasedOnDomainObjectType(
             resolveLinkTos,
             aggregateId);
         return(eventStoreConnection.SubscribeToStreamAsync(
                    streamName,
                    resolveLinkTos,
                    eventAppeared,
                    subscriptionDropped,
                    userCredentials).Result);
     }
     catch (Exception ex)
     {
         // Unlike a stream catch-up subscription, a live only subscription will fail if EventStore is not running.
         Log.Error(ex.Message);
         throw;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Connect to a single EventStore server with an IP address and a port
        /// </summary>
        /// <param name="credentials">UserCredentials: Username-Password used for authentication and authorization</param>
        /// <param name="serverIpEndPoint"><see cref="IPEndPoint"/>: IP address and port of the EventStore server</param>
        /// <param name="useTlsConnection">bool: Use an encrypted TLS connection to EventStore server. (optional, defaults to false.)</param>
        /// <param name="tlsCertificateHostName">string: The host name of the server expected on the TLS certificate. (optional unless <see cref="useTlsConnection"/> is true.)</param>
        /// <param name="validateTlsCertificate">bool: Validate the server TLS certificate. (optional, defaults to false. Used if <see cref="useTlsConnection"/> is true.)</param>
        /// <param name="verboseLogging">bool: Verbose Logging True/False (optional, defaults to false)</param>
        private void Connect(
            UserCredentials credentials,
            IPEndPoint serverIpEndPoint,
            bool useTlsConnection         = false,
            string tlsCertificateHostName = "",
            bool validateTlsCertificate   = false,
            bool verboseLogging           = false)
        {
            var settings = SetClientConnectionSettings(
                credentials,
                useTlsConnection,
                tlsCertificateHostName,
                validateTlsCertificate,
                verboseLogging);

            Connection = new EventStoreConnectionWrapper(
                EventStoreConnection.Create(settings, serverIpEndPoint, $"{serverIpEndPoint}-Single Connection")
                );
            if (Connection != null)
            {
                return;
            }
            _log.Error("Connection to EventStore is null,  - Diagnostic Monitoring will be unavailable.");
        }
Exemplo n.º 3
0
        public void Connect(
            UserCredentials credentials,
            IPAddress server,
            int tcpPort)
        {
            var tcpEndpoint = new IPEndPoint(server, tcpPort);

            var settings = ConnectionSettings.Create()
                           .SetDefaultUserCredentials(new global::EventStore.ClientAPI.SystemData.UserCredentials(credentials.Username, credentials.Password))
                           .KeepReconnecting()
                           .KeepRetrying()
                           .UseConsoleLogger()
                           //.EnableVerboseLogging()
                           .Build();

            Connection = new EventStoreConnectionWrapper(EventStoreConnection.Create(settings, tcpEndpoint, "Default Connection"));

            if (Connection == null)
            {
                _log.Error("EventStore Connection is null - Diagnostic Monitoring will be unavailable.");
                TeardownEventStore(false);
                return;
            }
            Connection.Connect();
            int retry = 8;
            int count = 0;

            do
            {
                try {
                    Connection.ReadStreamForward("by_event_type", 0, 1);
                    return;
                }
                catch {
                    //ignore
                }
                Thread.Sleep(100);
                count++;
            } while (count < retry);
            throw new Exception("Unable to start Eventstore");
        }