private void StartEventMessageConsumer() { //uri will give by a config item var _factory = new ConnectionFactory(); _factory.Uri = dispatcherSetting.RabbitMqConnectString; _factory.AutomaticRecoveryEnabled = true; var connection = _factory.CreateConnection(); var channelCounter = dispatcherSetting.QueuePoolSize; while (channelCounter > 0) { var itemNo = channelCounter - 1; var channel = connection.CreateModel(); var queueName = MQ_QUEUE_NAME + itemNo; channel.ExchangeDeclare(MQ_EXCHANAGE_NAME, ExchangeType.Direct, true, false, null); channel.QueueDeclare(queueName, true, false, false, null); channel.QueueBind(MQ_EXCHANAGE_NAME, queueName, string.Empty); var consumer = new EventMessageConsumer(channel, ProcessEventMessage, ProcessEventMessageFailed); channel.BasicQos(0, 1, false); channel.BasicConsume(queueName, false, consumer); consumerChannelDic.Add(queueName, new Tuple <IModel, EventMessageConsumer>(channel, consumer)); } }
private void ProcessAllUncommitEventMessageBeforeEventStoreDispatcherStartUp() { var _factory = new ConnectionFactory(); _factory.Uri = dispatcherSetting.RabbitMqConnectString; _factory.AutomaticRecoveryEnabled = true; var connection = _factory.CreateConnection(); var channelCounter = dispatcherSetting.QueuePoolSize; while (channelCounter > 0) { var itemNo = channelCounter - 1; var channel = connection.CreateModel(); var queueName = MQ_QUEUE_NAME + itemNo; channel.ExchangeDeclare(MQ_EXCHANAGE_NAME, ExchangeType.Direct, true, false, null); channel.QueueDeclare(queueName, true, false, false, null); channel.QueueBind(MQ_EXCHANAGE_NAME, queueName, string.Empty); var consumer = new EventMessageConsumer(channel, ProcessEventMessageOnStartUp, ProcessEventMessageFailed); channel.BasicQos(0, 1, false); channel.BasicConsume(queueName, false, consumer); tmpconsumerChannelDic.Add(queueName, new Tuple <IModel, EventMessageConsumer>(channel, consumer)); } Task.Factory.StartNew(() => { this.GetLogger("EventStoreDispatcherStartUp").Info("waiting proccess uncommit event message at {0}", DateTime.Now); while (slim.CurrentCount < dispatcherSetting.QueuePoolSize) { Task.Delay(1000).Wait(); } this.GetLogger("EventStoreDispatcherStartUp").Info("proccess uncommit event message end at {0}", DateTime.Now); }).Wait(); tmpconsumerChannelDic.AsParallel().ForAll(cc => cc.Value.Item1.Close()); tmpconsumerChannelDic.Clear(); }
private void StartEventMessageConsumer() { //uri will give by a config item var _factory = new ConnectionFactory(); _factory.Uri =dispatcherSetting.RabbitMqConnectString; _factory.AutomaticRecoveryEnabled = true; var connection = _factory.CreateConnection(); var channelCounter = dispatcherSetting.QueuePoolSize; while (channelCounter > 0) { var itemNo = channelCounter - 1; var channel = connection.CreateModel(); var queueName = MQ_QUEUE_NAME + itemNo; channel.ExchangeDeclare(MQ_EXCHANAGE_NAME, ExchangeType.Direct, true, false, null); channel.QueueDeclare(queueName, true, false, false, null); channel.QueueBind(MQ_EXCHANAGE_NAME, queueName, string.Empty); var consumer = new EventMessageConsumer(channel, ProcessEventMessage, ProcessEventMessageFailed); channel.BasicQos(0, 1, false); channel.BasicConsume(queueName, false, consumer); consumerChannelDic.Add(queueName, new Tuple<IModel, EventMessageConsumer>(channel, consumer)); } }
private void ProcessAllUncommitEventMessageBeforeEventStoreDispatcherStartUp() { var _factory = new ConnectionFactory(); _factory.Uri =dispatcherSetting.RabbitMqConnectString; _factory.AutomaticRecoveryEnabled = true; var connection = _factory.CreateConnection(); var channelCounter = dispatcherSetting.QueuePoolSize; while (channelCounter > 0) { var itemNo = channelCounter - 1; var channel = connection.CreateModel(); var queueName = MQ_QUEUE_NAME + itemNo; channel.ExchangeDeclare(MQ_EXCHANAGE_NAME, ExchangeType.Direct, true, false, null); channel.QueueDeclare(queueName, true, false, false, null); channel.QueueBind(MQ_EXCHANAGE_NAME, queueName, string.Empty); var consumer = new EventMessageConsumer(channel, ProcessEventMessageOnStartUp, ProcessEventMessageFailed); channel.BasicQos(0, 1, false); channel.BasicConsume(queueName, false, consumer); tmpconsumerChannelDic.Add(queueName, new Tuple<IModel, EventMessageConsumer>(channel, consumer)); } Task.Factory.StartNew(() => { this.GetLogger("EventStoreDispatcherStartUp").Info("waiting proccess uncommit event message at {0}", DateTime.Now); while (slim.CurrentCount < dispatcherSetting.QueuePoolSize) { Task.Delay(1000).Wait(); } this.GetLogger("EventStoreDispatcherStartUp").Info("proccess uncommit event message end at {0}", DateTime.Now); }).Wait(); tmpconsumerChannelDic.AsParallel().ForAll(cc => cc.Value.Item1.Close()); tmpconsumerChannelDic.Clear(); }