Example #1
0
        private async Task <bool> Process(CancellationToken cancellationToken)
        {
            var result = await _queueOperator.NextAsync(
                new QueueName(_actorDescriptor.SourceQueueName));

            if (result.IsSuccessful)
            {
                var actor = (IProcessorActor)_serviceLocator.GetService(_actorDescriptor.ActorType);
                try
                {
                    var events = (await actor.ProcessAsync(result.PollingResult)).ToArray();
                    await _queueOperator.CommitAsync(result.PollingResult);

                    var groups = events.GroupBy(x => x.QueueName);

                    foreach (var gr in groups)
                    {
                        await _queueOperator.PushBatchAsync(gr);
                    }
                }
                catch (Exception exception)
                {
                    Trace.TraceWarning(exception.ToString());
                    _queueOperator.AbandonAsync(result.PollingResult).SafeObserve();
                }
                finally
                {
                    _serviceLocator.ReleaseService(actor);
                }
            }

            return(result.IsSuccessful);
        }
Example #2
0
        private async Task <bool> Process(CancellationToken cancellationToken)
        {
            var result = await _queueOperator.NextAsync(
                new QueueName(_actorDescriptor.SourceQueueName));

            var cancellationTokenSource = new CancellationTokenSource();

            if (result.IsSuccessful)
            {
                TheTrace.TraceInformation("Receieved a message. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                var actor = (IProcessorActor)_serviceLocator.GetService(_actorDescriptor.ActorType);
                try
                {
                    // this is NOT supposed to be awaited upon!!
                    _queueOperator.KeepExtendingLeaseAsync(result.PollingResult, TimeSpan.FromSeconds(30),
                                                           cancellationTokenSource.Token).SafeObserve();

                    // Would have been great to make this fixed memory foot-print with real iterable vs. list
                    var events = (await actor.ProcessAsync(result.PollingResult)).ToArray(); // the enumerable has to be turned into a list anyway. it does further on
                    var groups = events.GroupBy(x => x.QueueName);

                    foreach (var gr in groups)
                    {
                        await _queueOperator.PushBatchAsync(gr);

                        TryDisposeMessages(gr);
                    }

                    cancellationTokenSource.Cancel();
                    await _queueOperator.CommitAsync(result.PollingResult);

                    TheTrace.TraceInformation("Processing succeeded. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                }
                catch (Exception exception)
                {
                    TheTrace.TraceInformation("Processing failed. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                    TheTrace.TraceError(exception.ToString());
                    cancellationTokenSource.Cancel();
                    _queueOperator.AbandonAsync(result.PollingResult).SafeObserve().Wait();
                }
                finally
                {
                    if (result.IsSuccessful)
                    {
                        TryDisposeMessage(result.PollingResult);
                    }
                    _serviceLocator.ReleaseService(actor);
                }
            }

            return(result.IsSuccessful);
        }
Example #3
0
        private async Task <bool> Process(CancellationToken cancellationToken)
        {
            var result = await _queueOperator.NextAsync(
                new QueueName(_actorDescriptor.SourceQueueName));

            var cancellationTokenSource = new CancellationTokenSource();

            if (result.IsSuccessful)
            {
                TheTrace.TraceInformation("Receieved a message. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                var actor = (IProcessorActor)_serviceLocator.GetService(_actorDescriptor.ActorType);
                try
                {
                    _queueOperator.KeepExtendingLeaseAsync(result.PollingResult, TimeSpan.FromSeconds(30),
                                                           cancellationTokenSource.Token).SafeObserve();

                    var events = (await actor.ProcessAsync(result.PollingResult)).ToArray();
                    cancellationTokenSource.Cancel();

                    await _queueOperator.CommitAsync(result.PollingResult);

                    var groups = events.GroupBy(x => x.QueueName);

                    foreach (var gr in groups)
                    {
                        await _queueOperator.PushBatchAsync(gr);

                        TryDisposeMessages(gr);
                    }

                    TheTrace.TraceInformation("Processing succeeded. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                }
                catch (Exception exception)
                {
                    TheTrace.TraceInformation("Processing failed. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                    TheTrace.TraceError(exception.ToString());
                    cancellationTokenSource.Cancel();
                    _queueOperator.AbandonAsync(result.PollingResult).SafeObserve().Wait();
                }
                finally
                {
                    if (result.IsSuccessful)
                    {
                        TryDisposeMessage(result.PollingResult);
                    }
                    _serviceLocator.ReleaseService(actor);
                }
            }

            return(result.IsSuccessful);
        }
Example #4
0
        private async Task <bool> Process(CancellationToken cancellationToken)
        {
            var result = await _queueOperator.NextAsync(
                new QueueName(_actorDescriptor.SourceQueueName));

            var cancellationTokenSource = new CancellationTokenSource();

            if (result.IsSuccessful)
            {
                TheTrace.TraceInformation("Received a message. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                var actor = (IProcessorActor)_serviceLocator.GetService(_actorDescriptor.ActorType);
                try
                {
                    // this is NOT supposed to be awaited upon!!
                    if (!_queueOperator.IsEventDriven)
                    {
                        _queueOperator.KeepExtendingLeaseAsync(result.PollingResult, TimeSpan.FromSeconds(30),
                                                               cancellationTokenSource.Token).SafeObserve();
                    }

                    await ProcessEvent(actor, result.PollingResult, _queueOperator);

                    if (!_queueOperator.IsEventDriven)
                    {
                        await _queueOperator.CommitAsync(result.PollingResult);
                    }

                    TheTrace.TraceInformation("Processing succeeded. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                }
                catch (Exception exception)
                {
                    TheTrace.TraceInformation("Processing failed. Id: {0} Queue: {1} ", result.PollingResult.Id, _actorDescriptor.SourceQueueName);
                    TheTrace.TraceError(exception.ToString());
                    cancellationTokenSource.Cancel();
                    _queueOperator.AbandonAsync(result.PollingResult).SafeObserve().Wait();
                }
                finally
                {
                    if (result.IsSuccessful)
                    {
                        TryDisposeMessage(result.PollingResult);
                    }
                    _serviceLocator.ReleaseService(actor);
                }
            }

            return(result.IsSuccessful);
        }