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);
        }
Example #2
0
        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 => { }, () => { });
        }
Example #3
0
 private void Publish(T message)
 {
     lock (_buffer)
     {
         //see comment in FlushBuffer
         _consumer.Handle(message);
     }
 }
Example #4
0
 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);
     });
 }
Example #6
0
        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);
        }
Example #7
0
 public virtual void SetUp()
 {
     consumer = GivenConsumer();
     try {
         published = When();
         if (published != null)
         {
             consumer.Handle(published);
         }
     }
     catch (Exception Ex) {
         caught = Ex;
     }
 }
Example #8
0
 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();
        }
Example #11
0
 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?
             //??
         }
     }
 }
Example #12
0
 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?
         }
     }
 }
Example #13
0
 public void Handle(TConsumes message)
 {
     _inner.Handle((TProduces)message);
 }
Example #14
0
 public void Handle(TIn message)
 {
     _consumer.Handle(message);
 }
 private void Backlog(T @event)
 {
     _backlogConsumer.Handle(@event);
 }