Example #1
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);
            var queues = client.GetAllQueues().ToArray();

            WriteObject(queues);
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);

            var nodes = client.GetClusterNodes();

            WriteObject(nodes);
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);

            var clusterName = client.GetHealthCheck();

            WriteObject(clusterName);
        }
Example #4
0
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);

            var policy = GetPolicy(GetPolicyDefinition());

            client.CreatePolicy(VirtualHost, Name, policy);

            WriteVerbose("Policy settings:");
            policy.definition.OrderBy(pd => pd.Key).ToList().ForEach(dv => WriteVerbose($"{dv.Key} = {dv.Value}"));

            WriteVerbose("Policy created/updated");
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);

            int[] allPorts  = { Port };
            int[] livePorts = { Port };

            if (FirewallConfigured || ShouldContinue(
                    $"Do you have private/domain firewall ports {string.Join(", ", allPorts)} open on this and the other RabbitMq node?",
                    "Firewall"))
            {
                WriteVerbose("Firewall/network access marked as configured");
            }
            else
            {
                throw new ApplicationException("Network access not configured");
            }

            WriteVerbose("Checking ports");

            using (var tcpClient = new TcpClient())
            {
                livePorts.ToList().ForEach(p =>
                {
                    try
                    {
                        WriteVerbose($"Validating connection to {Hostname} on port {p}");

                        tcpClient.Connect(Hostname, p);

                        tcpClient.Close();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Failed to connect to {Hostname} on port {p}", ex);
                    }
                });
            }

            WriteVerbose("Checking credentials");

            try
            {
                using (var connection = this.GetConnection(Hostname, Credential.UserName, Credential.GetNetworkCredential().Password, false, Port))
                {
                    using (var model = connection.CreateModel())
                    {
                        if (model.IsOpen)
                        {
                            WriteVerbose("Connection successful");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Connection failed. There might be an issue with the installation. Please check the RabbitMq log files:" + ex.Message, ex);
            }

            WriteVerbose($"Federating {Environment.MachineName} to {Hostname} upstream ");

            var uriBuild = new UriBuilder
            {
                Scheme   = "amqp",
                Host     = Hostname,
                Port     = Port,
                UserName = Uri.EscapeDataString(Credential.UserName),
                Password = Credential.GetNetworkCredential().Password
            };

            //get rid of trailing slashes
            var uriString = uriBuild.Uri.ToString().TrimEnd('/');

            var parameters = new ComponentParameters
            {
                component = ComponentParameterOptions.Federation.Component,
                name      = Name,
                value     = new Dictionary <string, object>
                {
                    { ComponentParameterOptions.Federation.ParameterKeys.AckMode, ComponentParameterOptions.Federation.AckModes.OnConfirm },

                    { ComponentParameterOptions.Federation.ParameterKeys.PreFetchCount, PreFetchCount },
                    { ComponentParameterOptions.Federation.ParameterKeys.ReconnectDelay, ReconnectDelay },
                    { ComponentParameterOptions.Federation.ParameterKeys.Expires, Expires },
                    { ComponentParameterOptions.Federation.ParameterKeys.TrustUserId, false },
                    { ComponentParameterOptions.Federation.ParameterKeys.Uri, uriString }
                }
            };

            client.CreateFederationUpstream(VirtualHost, Name, parameters);


            //remove the uri since it has a username and password
            parameters.value[ComponentParameterOptions.Federation.ParameterKeys.Uri] = "[redacted]";

            WriteVerbose("Policy settings:");
            parameters.value.OrderBy(pd => pd.Key).ToList().ForEach(dv => WriteVerbose($"{dv.Key} = {dv.Value}"));


            WriteVerbose("Upstream created/updated");
        }
        /// <summary>
        ///     Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            var client = new RabbitMqRestClient(BaseUrl, AdminCredential.UserName,
                                                AdminCredential.GetNetworkCredential().Password);
            var queues = client.GetAllQueues().ToArray();

            if (!queues.Any())
            {
                WriteVerbose("There are no queues to remove");
                return;
            }

            var          activityid = ActivityIdProvider.GetNextActivityId();
            const string activity   = "Removing";

            WriteProgress(new ProgressRecord(activityid, activity, "Removing all queues")
            {
                PercentComplete = 5
            });

            var orderedQueues = queues.OrderBy(q => q.vhost).ThenBy(q => q.name).ToList();
            var c             = 0;
            var total         = orderedQueues.Count;

            var statuses = new List <KeyValuePair <string, string> >();

            orderedQueues.ForEach(q =>
            {
                if (q.auto_delete || q.exclusive)
                {
                    WriteVerbose($"Skipping {q.name} on {q.vhost}");
                    c++;
                    return;
                }

                WriteProgress(new ProgressRecord(activityid, activity, $"Removing {q.name} on {q.vhost}")
                {
                    PercentComplete = Convert.ToInt32(Convert.ToDouble(c) / total * 100)
                });
                WriteVerbose($"Removing {q.name} on {q.vhost}");

                try
                {
                    client.DeleteQueue(q.vhost, q.name);
                    statuses.Add(new KeyValuePair <string, string>(q.name, HttpStatusCode.OK.ToString()));
                }
                catch (Exception ex)
                {
                    statuses.Add(new KeyValuePair <string, string>(q.name, ex.Message));
                }

                c++;
            });

            WriteObject(statuses);

            WriteProgress(new ProgressRecord(activityid, activity, "Removed all queues")
            {
                PercentComplete = 100,
                RecordType      = ProgressRecordType.Completed
            });
        }