Пример #1
0
        private void InitializeMessagingProcessor(string topicKey, DateTime date)
        {
            if (connectors[topicKey].ThreadingPool.AreThreadsRunning != true)
            {
                connectors[topicKey].ThreadingPool.AreThreadsRunning = true;

                // Wait until is connected to DB.
                int timeOutCounter = 0;
                if (connectors[topicKey].MessageContext == null)
                {
                    var topicData = topicKey.Split("~");
                    connectors[topicKey].MessageContext = new MessageContext(MessageLocations.GetMessagePartitionFile(topicData[0],
                                                                                                                      topicData[1], topicData[2], topicData[3], date));
                    connectors[topicKey].CreateMessageFile();

                    while (connectors[topicKey].MessageContext.Database.CanConnect() != true)
                    {
                        timeOutCounter++;
                        Thread.Sleep(500);
                        _logger.LogWarning($"Message Storage Service for '{topicKey}' stopped working, trying to start {timeOutCounter} of 10");
                        if (timeOutCounter == 10)
                        {
                            connectors[topicKey].ThreadingPool.AreThreadsRunning = false;
                            return;
                        }
                    }
                }

                InitialzeThreads(topicKey);
            }
        }
Пример #2
0
        public MessageContext GetPartitionMessageContext(string topicKey, DateTime date)
        {
            // Wait until is connected to DB.
            int timeOutCounter = 0;

            if (connectors[topicKey].MessageContext == null)
            {
                var topicData = topicKey.Split("~");
                connectors[topicKey].MessageContext = new MessageContext(MessageLocations.GetMessagePartitionFile(topicData[0],
                                                                                                                  topicData[1], topicData[2], topicData[3], date));
                connectors[topicKey].CreateMessageFile();

                while (connectors[topicKey].MessageContext.Database.CanConnect() != true)
                {
                    timeOutCounter++;
                    Thread.Sleep(500);
                    _logger.LogWarning($"Message Storage Service for '{topicKey}' stopped working, trying to start {timeOutCounter} of 10");
                    if (timeOutCounter == 10)
                    {
                        return(null);
                    }
                }
            }

            return(connectors[topicKey].MessageContext);
        }