configurator.ReceiveEndpoint(host, "search_people_delta_queue", e =>{e.UseConcurrencyLimit(1, null, null);e.Consumer(() => new SearchPeopleCoreDeltaConsumer());e.PrefetchCount = 1;});
public Task Consume(ConsumeContext<SolrPeopleDeltaMessage> context) { var successfullyWaited = Infrastructure.Utils.SolrUtility.WaitForSolr(Cores.People);
var solrParameter = context.Message.SolrParameter; var solrIdParameter = (IdParameters)Enum.Parse(typeof(IdParameters), solrParameter); var solrParameterValue = context.Message.SolrParameterValue;
if (!successfullyWaited) { _loggingService.Log(string.Format("Solr People Core was not ready in time to receive delta index request for {0} = {1}", solrIdParameter, solrParameterValue), LogLevel.Info); }
else { _loggingService.Log(string.Format("Solr People Core reports ready to index. Delta indexing {0} = {1}", solrIdParameter, solrParameterValue), LogLevel.Info);
string peopleCoreDeltaUrl = SolrUtility.DeltaUrlFor(Cores.People, solrIdParameter, solrParameterValue);
var response = SolrUtility.GetResponse(peopleCoreDeltaUrl); }
return context.CompleteTask; }
public static bool WaitForSolr(Cores core) { bool solrIsCurrent = false; int numberAttempts = 0;
int secondsUntilRetry = 5;
//Minutes x 60 = seconds, divide by seconds until retry = maximum allowed number of attempts. int maxNumberAttempts = (int) Math.Ceiling(double.Parse(AppSettings.SolrMaximumDeltaWaitMinutes) * 60 / secondsUntilRetry);
// Attempts will be made every few seconds. The above calculations tell us how many attempts we get based // on the maximum amount of minutes we're willing to wait. while (!solrIsCurrent && numberAttempts <= maxNumberAttempts) { var solrStatus = Core.Data.Solr.SolrUtility.GetCoreStatus(core); var solrStatusXml = XDocument.Parse(solrStatus);
// I happen to know that the XML that comes back from Solr has an element that // looks like <bool name="current">true or false</bool> // We want to know when this is "true", because that means Solr is current and // that means we can now do another index. var currentValue = solrStatusXml.Descendants("bool") .Single(x => (string)x.Attribute("name") == "current") .Value;
solrIsCurrent = bool.Parse(currentValue);
// If Solr is not current, wait a few seconds before asking again. if (!solrIsCurrent) { Thread.Sleep(secondsUntilRetry * 1000); numberAttempts++; } }
return solrIsCurrent;