public virtual ObservingProducer <T> Produces(IObservable <T> sequence, Action <Exception> onError = null, Action onCompleted = null) { var observer = new DelegatingObserver <T>(@event => _consumer.Handle(@event), onError ?? (exception => { }), onCompleted ?? (() => { })); _cache.Add(observer, sequence); return(this); }
public void Subscribe <T>(Consumes <T> consumer, Func <T, bool> topic) { var subscription = GetSubscriptionSubject <T>(); var observable = Box <T>(subscription).Where(topic).AsObservable(); observable.Subscribe(@event => consumer.Handle(@event), exception => { }, () => { }); }
private void Publish(T message) { lock (_buffer) { //see comment in FlushBuffer _consumer.Handle(message); } }
public static void TryConsume <T>(this Consumes <T> consumer, T message) where T : Message { if (consumer == null) { return; } consumer.Handle(message); }
private async void HandleUndeliverable(T @event) { await Task.Factory.StartNew(() => { _undeliverableConsumer.Handle(@event); Interlocked.Increment(ref _undelivered); }); }
public void Subscribe <T>(Consumes <T> consumer) { var subscription = GetSubscriptionSubject <T>(); var observable = Box <T>(subscription).AsObservable(); var unsubscription = _unsubscriptions.GetOrAdd(typeof(T), t => new CancellationTokenSource()); observable.Subscribe(@event => consumer.Handle(@event), exception => { }, () => { }, unsubscription.Token); }
public virtual void SetUp() { consumer = GivenConsumer(); try { published = When(); if (published != null) { consumer.Handle(published); } } catch (Exception Ex) { caught = Ex; } }
public void Handle(T message) { if (!Monitor.TryEnter(_lockObject, _timeout)) { throw new UnableToAcquireLockException(); } try { _consumer.Handle(message); } finally { Monitor.Exit(_lockObject); } }
public DelegatingConsumer(Action <T> @delegate, Consumes <T> forwardTo) { _delegate = @event => { try { @delegate(@event); return(forwardTo.Handle(@event)); } catch (Exception) { return(false); } }; }
private void ProductionCycle(ParallelOptions options, T @event, ParallelLoopState state) { if (state.ShouldExitCurrentIteration) { Backlog(@event); return; } if (!_consumer.Handle(@event)) { HandleUnsuccessfulDelivery(options, @event, state); } Interlocked.Increment(ref _sent); options.CancellationToken.ThrowIfCancellationRequested(); }
private void Run() { while (true) { try { T item; if (_queue.TryDequeue(out item)) { _consumer.Handle(item); _queue.MarkComplete(item); } } catch (Exception Ex) { //Todo: Add log4net //Dead letter //Stop? //?? } } }
private void Run() { while (true) { try { T item; var current = new List <T>(); lock (_queue) { while (_queue.Count > 0) { item = _queue.Dequeue(); current.Add(item); } } current.ForEach(x => _consumer.Handle(x)); Thread.Sleep(_sleepMilliseconds); } catch (Exception Ex) { //what to do with errors at this point? } } }
public void Handle(TConsumes message) { _inner.Handle((TProduces)message); }
public void Handle(TIn message) { _consumer.Handle(message); }
private void Backlog(T @event) { _backlogConsumer.Handle(@event); }