public async Task StartEventProcessorHost(string connectionString, params string[] queueNames)
        {
            _logger.Information(AppendingPrimaryKeyInfoToMessage(string.Format("StartEventProcessorHost() enter. ConnectionString: {0}", connectionString)));

            _orleansTaskScheduler = TaskScheduler.Current;
            try
            {
                if (_queueListner == null)
                {
                    var reminderName = string.Format("{0}", "keepalive");
                    await RegisterOrUpdateReminder(reminderName, new TimeSpan(0, 10, 0), new TimeSpan(0, 10, 0));

                    _queueListner = new RabbitMqQueueListener(connectionString, queueNames);
                    await Task.Run(() => _queueListner.Start(queueNames).WithMessageAction(queueNames, (queueName, message) =>
                    {
                        return(Task.Factory.StartNew(() =>
                        {
                            var processor = GrainFactory.GetGrain <IEventProcessorGrain>(queueName);
                            return processor.ProcessMessage(message);
                        }, CancellationToken.None, TaskCreationOptions.None, _orleansTaskScheduler));
                    }));
                }
            }
            catch (RabbitMQException rabbitmqEx)
            {
                _logger.Error(rabbitmqEx);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            _logger.Information(AppendingPrimaryKeyInfoToMessage("StartEventProcessorHost() exit."));
        }
Exemplo n.º 2
0
        public void  StartProcessing()
        {
            try
            {
                GrainClient.Initialize("ClientOrleansConfiguration.xml");

                Task.Run(() =>
                {
                    _queueListener = new RabbitMqQueueListener(ConnectionConst.AmqpConnection, ConnectionConst.CommandQueue, true);
                    var processor  = GrainClient.GrainFactory.GetGrain <IEventProcessorGrain>(ConnectionConst.CommandQueue);
                    _queueListener.Start().WithMessageAction((message) =>
                    {
                        return(processor.ProcessMessage(message));
                    });
                });
            }
            catch (Exception ex)
            {
            }
        }