private static ControlQueue GetControlQueue(string queuename, string hostname, string username, string password) { try { QueueConnectionProvider queueConnectionProvider = new QueueConnectionProvider(); queueConnectionProvider.UserName = username; queueConnectionProvider.PassWord = password; queueConnectionProvider.HostName = hostname; ControlQueue _controlQueue = new ControlQueue(); _controlQueue.ConnectionProvider = queueConnectionProvider; _controlQueue.QueueName = queuename; _controlQueue.CreateQueue(); return(_controlQueue); } catch (Exception e) { throw e.InnerException; } }
public T Read() { T item = null; string data = null; bool firstTimeout = true; _maxNumberOfPolls = MaxNumberOfPolls; while (_maxNumberOfPolls > 0) { // Read Message from the dataQueue BasicGetResult result = _dataQueue.Channel.BasicGet(_dataQueue.QueueName, true); if (result != null) { try { // Deserialize message to business object item = SerializationUtils.DeserializeObject <T>(result.Body.ToArray()); break; } catch (Exception ex) { _logger.Debug("Json Serialize failed. Reason: " + ex.StackTrace); throw; } } else { // If there is no data to poll, wait for master step _logger.Debug("Wait for {0} second for dataQueue, check for master part is completed or not", PollingTimeOut); Thread.Sleep(TimeSpan.FromSeconds(PollingTimeOut)); _logger.Debug("Polling of number : {0}", _maxNumberOfPolls); // For the first timeout , check master step is completed if (!string.IsNullOrWhiteSpace(MasterName)) { if (_masterqueue == null) { _masterqueue = new ControlQueue(); QueueConnectionProvider queueConnectionProvider = new QueueConnectionProvider(); queueConnectionProvider.UserName = _dataQueue.UserName; queueConnectionProvider.PassWord = _dataQueue.PassWord; queueConnectionProvider.HostName = _dataQueue.HostName; _masterqueue.ConnectionProvider = queueConnectionProvider; _masterqueue.QueueName = "master"; _masterqueue.CreateQueue(); } string MasterCompletedMessage = "master" + dot + MasterName + dot + "COMPLETED"; if (firstTimeout) { _logger.Debug("First Timeout need to check the master process is completed. "); firstTimeout = false; if (_masterqueue.CheckMessageExistAndConsume(MasterCompletedMessage)) { _logger.Debug("There is no more data to read for worker."); break; } _logger.Debug("Need to wait for master to completed."); } } _maxNumberOfPolls--; } } return(item); }