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(); }
public void Connect() { _eventStoreConnection.ConnectAsync().Wait(); CreatePersistentSubscription(_eventStoreConnection); EventStorePersistentSubscriptionBase = _eventStoreConnection.ConnectToPersistentSubscription(StreamName, GroupName, EventAppeared, SubscriptionDropped, _userCredentials); }
public void ConnectToSubscription() { var bufferSize = 10; var autoAck = true; _subscription = _conn.ConnectToPersistentSubscription(_stream, _group, EventAppeared, SubscriptionDropped, User, bufferSize, autoAck); }
private void ConnectToSubscription() { var bufferSize = 10; var autoAck = true; _subscription = _conn.ConnectToPersistentSubscription(STREAM, GROUP, EventAppeared, SubscriptionDropped, User, bufferSize, autoAck); }
private void ConnectToSubscription() { var bufferSize = 10; var autoAck = true; _subscription = _conn.ConnectToPersistentSubscription(STREAM, GROUP, (Action <EventStorePersistentSubscriptionBase, ResolvedEvent>)EventAppeared, SubscriptionDropped, User, bufferSize, autoAck); }
public void Connect() { var streamName = $"$ce-{typeof(T).Name}"; EventStorePersistentSubscriptionBase = _eventStoreConnection.ConnectToPersistentSubscription( streamName, _groupName, EventAppeared, SubscriptionDropped ); }
private void ConnectToSubscription() { var bufferSize = 10; var autoAck = true; Console.WriteLine("**** Connecting to subscription ..."); _subscription = _conn.ConnectToPersistentSubscription(STREAM, GROUP, (_base, _event) => { EventAppeared(_base, _event); }, (_base, _reason, _exception) => { SubscriptionDropped(_base, _reason, _exception); }, User, bufferSize, autoAck); }
public void Start() { Console.WriteLine("Start service"); CreateESConnection(); PrepareDictionary(); _connectionES.ConnectToPersistentSubscription( "picture_stream", "PictureScan", (_, x) => DoSomething(_, x), (sub, reason, ex) => { }, _connectionES.Settings.DefaultUserCredentials); }
protected override async Task Given() { _conn = EventStoreConnection.Create(_node.TcpEndPoint); await _conn.ConnectAsync(); await _conn.CreatePersistentSubscriptionAsync(_streamName, _groupName, _settings, DefaultData.AdminCredentials); _sub1 = _conn.ConnectToPersistentSubscription(_streamName, _groupName, (subscription, @event) => { Console.WriteLine(); return(Task.CompletedTask); }, (subscription, reason, arg3) => Console.WriteLine(), DefaultData.AdminCredentials); _sub2 = _conn.ConnectToPersistentSubscription(_streamName, _groupName, (subscription, @event) => { Console.WriteLine(); return(Task.CompletedTask); }, (subscription, reason, arg3) => Console.WriteLine(), DefaultData.AdminCredentials); }
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 ConnectToSubscription(Projection projection) { var bufferSize = 10; var autoAck = true; var subscription = eventStoreConnection.ConnectToPersistentSubscription( projection.ToString(), Group, EventAppeared(projection), SubscriptionDropped(projection), userCredentials, bufferSize, autoAck); eventStorePersistentSubscriptionBases.Add(subscription); }
/// <summary> /// Subscribes to a persistent subscription(competing consumer) on event store /// </summary> /// <param name="target">The connection to subscribe to</param> /// <param name="groupName">The subscription group to connect to</param> /// <param name="stream">The stream to subscribe to</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> /// <param name="bufferSize">The buffer size to use for the persistent subscription</param> /// <param name="autoAck">Whether the subscription should automatically acknowledge messages processed. /// If not set the receiver is required to explicitly acknowledge messages through the subscription.</param> /// <remarks>This will connect you to a persistent subscription group for a stream. The subscription group /// must first be created with CreatePersistentSubscriptionAsync many connections /// can connect to the same group and they will be treated as competing consumers within the group. /// If one connection dies work will be balanced across the rest of the consumers in the group. If /// you attempt to connect to a group that does not exist you will be given an exception. /// </remarks> /// <returns>An <see cref="EventStorePersistentSubscriptionBase"/> representing the subscription</returns> public static EventStorePersistentSubscriptionBase ConnectToPersistentSubscription( this IEventStoreConnection target, string stream, string groupName, Action <EventStorePersistentSubscriptionBase, ResolvedEvent> eventAppeared, Action <EventStorePersistentSubscriptionBase, SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null, int bufferSize = 10, bool autoAck = true) => target.ConnectToPersistentSubscription( stream, groupName, ToTask(eventAppeared), subscriptionDropped, userCredentials, bufferSize, autoAck );
private async Task SubscribeProcessManager(AppFunc chain, IManageProcess currentProcessManager, IDictionary <string, object> environment) { environment.Log("Subscribing processmanager: {0}", LogLevel.Debug, currentProcessManager.ProcessName); while (true) { if (!running) { return; } if (_processManagerSubscriptions.ContainsKey(currentProcessManager.ProcessName)) { _processManagerSubscriptions[currentProcessManager.ProcessName].Close(); _processManagerSubscriptions.Remove(currentProcessManager.ProcessName); } try { var eventStoreSubscription = _eventStoreConnection.ConnectToPersistentSubscription(currentProcessManager.ProcessName, currentProcessManager.ProcessName, async(subscription, evnt) => await PushEventToProcessManager(chain, currentProcessManager, _eventSerialization.DeSerialize(evnt), environment, subscription).ConfigureAwait(false), async(subscription, reason, exception) => await SubscriptionDropped(chain, currentProcessManager, reason, exception, environment).ConfigureAwait(false), autoAck: false); _processManagerSubscriptions[currentProcessManager.ProcessName] = new ProcessManagerSubscription(eventStoreSubscription); return; } catch (Exception ex) { if (!running) { return; } environment.Log(ex, "Couldn't subscribe processmanager: {0}. Retrying in 5 seconds.", LogLevel.Error, currentProcessManager.ProcessName); await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); } } }
static void InventaryManager(IEventStoreConnection conn, string streamName, UserCredentials userCredentials) { //Existing events var streamEvents = conn.ReadStreamEventsForwardAsync(streamName, 0, 10, true, userCredentials).Result; foreach (var evt in streamEvents.Events) { var json = Encoding.UTF8.GetString(evt.Event.Data); dynamic sales = JsonConvert.DeserializeObject(json); Console.WriteLine("Product : {0}, Quantity : {1}", sales.ProductName, sales.Quantity); } //Listening for new events Console.WriteLine("\nListening for new sales...\n"); conn.ConnectToPersistentSubscription(streamName, "inventaryManager", (_, x) => { var data = Encoding.ASCII.GetString(x.Event.Data); dynamic sales = JsonConvert.DeserializeObject(data); Console.WriteLine("New\tProduct : {0}, Quantity : {1}", sales.ProductName, sales.Quantity); }, (sub, reason, ex) => { }, userCredentials); }
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); }
public void Initialize() { _connection.ConnectToPersistentSubscription(_subscription.StreamName, _subscription.GroupName, OnEventAppeared); }
private void SubscribePersisten() { _conn.ConnectToPersistentSubscription(_streamName, "transactionReadModelWriter", GotEvent, subscriptionDropped: Dropped, autoAck: true); }
private async Task SubscribeService(AppFunc chain, string stream, bool liveOnlySubscriptions, string subscriptionKey, IDictionary <string, object> environment) { environment.Log("Subscribing to stream: {0}", LogLevel.Debug, stream); while (true) { if (!running) { return; } try { if (_serviceSubscriptions.ContainsKey(subscriptionKey)) { _serviceSubscriptions[subscriptionKey].Close(); _serviceSubscriptions.Remove(subscriptionKey); } if (liveOnlySubscriptions) { //TODO:Handle retries on error var eventstoreSubscription = await _eventStoreConnection.SubscribeToStreamAsync(stream, true, async (subscription, evnt) => await PushEventToService(chain, stream, _eventSerialization.DeSerialize(evnt), false, environment, x => environment.Log("Successfully handled event: {0} on stream: {1}", LogLevel.Debug, x.EventId, stream), (x, exception) => environment.Log(exception, "Failed handling event: {0} on stream: {1}", LogLevel.Error, x.EventId, stream)).ConfigureAwait(false), async (subscription, reason, exception) => await SubscriptionDropped(chain, stream, true, subscriptionKey, reason, exception, environment).ConfigureAwait(false)).ConfigureAwait(false); _serviceSubscriptions[subscriptionKey] = new LiveOnlyServiceSubscription(eventstoreSubscription); } else { var eventstoreSubscription = _eventStoreConnection.ConnectToPersistentSubscription(stream, subscriptionKey, async(subscription, evnt) => await PushEventToService(chain, stream, _eventSerialization.DeSerialize(evnt), true, environment, x => { environment.Log("Successfully handled event: {0} on stream: {1}", LogLevel.Debug, x.EventId, stream); subscription.Acknowledge(x.OriginalEvent); }, (x, exception) => { environment.Log(exception, "Failed handling event: {0} on stream: {1}", LogLevel.Error, x.EventId, stream); subscription.Fail(x.OriginalEvent, PersistentSubscriptionNakEventAction.Unknown, exception.Message); }).ConfigureAwait(false), async(subscription, reason, exception) => await SubscriptionDropped(chain, stream, false, subscriptionKey, reason, exception, environment).ConfigureAwait(false), autoAck: false); _serviceSubscriptions[subscriptionKey] = new PersistentServiceSubscription(eventstoreSubscription); } return; } catch (Exception ex) { if (!running) { return; } environment.Log(ex, "Couldn't subscribe to stream: {0}. Retrying in 5 seconds.", LogLevel.Warn, stream); await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); } } }