Example #1
0
        public override bool OnStart()
        {
            var readPath = RoleEnvironment.GetLocalResource("ReadStorage").RootPath;
            var writePath = RoleEnvironment.GetLocalResource("WriteStorage").RootPath;

            var subscription = "lucene" ;
            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Blob"));
            var hub = new Hub(RoleEnvironment.GetConfigurationSettingValue("ServiceBus"));

            var criticalWait = Task.Run(() =>
            {
                string writeFolder = Path.Combine(writePath, "lucene");
                if (!System.IO.Directory.Exists(writeFolder))
                {
                    System.IO.Directory.CreateDirectory(writeFolder);
                }
                string combine = Path.Combine(readPath, subscription);
                if (!System.IO.Directory.Exists(combine))
                {
                    System.IO.Directory.CreateDirectory(combine);
                }

                var localDirectory = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(combine));
                var masterDirectory = new AzureDirectory(account, subscription);
                var irs = new IntermediateReaderService(masterDirectory, hub, localDirectory, true);

                masterDirectory.Dispose();

                return new IndexInfo {IRS = irs as IDisposable, Directory = localDirectory};
            })
                .ContinueWith(t => _localIndexes = new[] {t.Result});

            _luceneWriter = new SearchWriterService(new AzureDirectory(account, "lucene", new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(writePath))), true);
            var subscriptionName = string.Format("{0:yyyyMMddHHmmss}_{1}", DateTime.UtcNow, Guid.NewGuid().ToString().Replace("-", string.Empty));
            hub.CreateSubscription("lucene", subscriptionName)
                .ContinueWith(t =>
                {
                    _luceneTempInstanceSubscription = t.Result;
                    return hub.SubscribeWithRoutingKey("lucene", subscriptionName, OnSearchMessage)
                        .ContinueWith(t2 => _luceneSearchSubscription = t.Result);
                })
                .Unwrap();

            return base.OnStart();
        }
Example #2
0
        private BrokeredMessageResults Message(GenericPayloadDeliverInfo genericPayloadDeliverInfo)
        {
            var body = genericPayloadDeliverInfo.Payload.GetBody <GenericSearchItem>().GetBody();

            _writer.UpdateDocument(SearchWriterService.GetTerm(body), SearchWriterService.GetDocument(body));
            if (!_enableNearRealTimeCache)
            {
                _writer.Commit();
            }
            else
            {
                lock (Sync)
                {
                    HasEntitites++;
                }
            }

            return(BrokeredMessageResults.NoMatter);
        }