public ProtoClusterRxBroker(IClusterProvider clusterProvider)
        {
            Props props = Actor.FromProducer(() => new BrokerMasterActor());

            Remote.RegisterKnownKind(nameof(BrokerMasterActor), props);
            Serialization.RegisterFileDescriptor(BrokerReflection.Descriptor);

            Remote.Start("127.0.0.1", PortUtils.FindAvailablePort());
            //Cluster.Start("MyCluster", clusterProvider);

            //PID brokerMasterPid = Cluster.GetAsync("Master", nameof(BrokerMasterActor)).Result;
            //Cluster.GetAsync("Master2", nameof(BrokerMasterActor)).Wait();
            //Cluster.GetAsync("Master" + Guid.NewGuid(), nameof(BrokerMasterActor)).Wait();

            //props = Actor.FromProducer(() => new BrokerActor(brokerMasterPid));
            //_brokerPid = Actor.SpawnNamed(props, "Broker");
        }
Exemple #2
0
        public static void Install(int port = 0, string installPath = null)
        {
            if (string.IsNullOrEmpty(installPath))
            {
                installPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Replace(" (x86)", String.Empty), DefaultDirectoryName);
            }

            if (Directory.Exists(installPath))
            {
                Console.Out.WriteLine("Path '{0}' already exists please update RavenDB manually if needed.", installPath);
                return;
            }

            var serviceName = "RavenDB";

            var service = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName);

            if (service != null)
            {
                Console.Out.WriteLine("There is already a RavenDB service installed on this computer, the RavenDB service status is {0}.", service.Status);

                if (IsRavenDBv2RunningOn(8080)) //todo: we can improve this in the future by looking into the config file to try to figure out the port
                {
                    Console.Out.WriteLine("Existing Raven is v2, NServiceBus will be configured to use it");

                    SavePortToBeUsedForRavenInRegistry(8080);

                    return;
                }

                serviceName = serviceName + "-v2";
            }

            int availablePort;

            //Check if the port is available, if so let the installer setup raven if its being run
            if (port > 0)
            {
                availablePort = PortUtils.FindAvailablePort(port);
                if (availablePort != port)
                {
                    if (IsRavenDBv2RunningOn(port))
                    {
                        Console.Out.WriteLine("A compatible(v2) version of Raven has been found on port {0} and will be used", port);

                        SavePortToBeUsedForRavenInRegistry(port);
                    }
                    else
                    {
                        Console.Out.WriteLine("Port '{0}' isn't available, please specify a different port and rerun the command.", port);
                    }

                    return;
                }
            }
            else
            {
                availablePort = PortUtils.FindAvailablePort(DefaultPort);

                //is there already a Raven2 on the default port?
                if (availablePort != DefaultPort && IsRavenDBv2RunningOn(DefaultPort))
                {
                    Console.Out.WriteLine("A compatible(v2) version of Raven has been found on port {0} and will be used", DefaultPort);

                    SavePortToBeUsedForRavenInRegistry(DefaultPort);
                    return;
                }
            }

            if (!RavenHelpers.EnsureCanListenToWhenInNonAdminContext(availablePort))
            {
                Console.WriteLine("Failed to grant rights for listening to http on port {0}, please specify a different port and rerun the command.", availablePort);
                return;
            }

            if (!Directory.Exists(installPath))
            {
                Directory.CreateDirectory(installPath);
            }

            Console.WriteLine("Unpacking resources...");

            ExportRavenResources(installPath);

            var ravenConfigPath = Path.Combine(installPath, "Raven.Server.exe.config");
            var ravenConfig     = new XmlDocument();

            ravenConfig.Load(ravenConfigPath);

            var key = (XmlElement)ravenConfig.DocumentElement.SelectSingleNode("//add[@key='Raven/Port']");

            key.SetAttribute("value", availablePort.ToString(CultureInfo.InvariantCulture));

            ravenConfig.Save(ravenConfigPath);
            Console.Out.WriteLine("Updated Raven configuration to use port {0}.", availablePort);

            SavePortToBeUsedForRavenInRegistry(availablePort);

            Console.WriteLine("Installing RavenDB as a windows service.");

            var startInfo = new ProcessStartInfo
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                WorkingDirectory       = installPath,
                Arguments = "--install --service-name=" + serviceName,
                FileName  = Path.Combine(installPath, "Raven.Server.exe")
            };

            using (var process = Process.Start(startInfo))
            {
                process.WaitForExit(20000);

                var line = process.StandardOutput.ReadToEnd();
                Console.WriteLine(line);

                if (process.ExitCode != 0)
                {
                    Console.WriteLine("The RavenDB service failed to start, Raven.Server.exe exit code was {0}.", process.ExitCode);
                    return;
                }
            }

            Console.WriteLine("{0} service started, listening on port: {1}", serviceName, availablePort);
        }