Example #1
0
        public void OnTimer(object state)
        {
            var brokers = dbReader.Get <Broker> ("Active = TRUE");

            foreach (var broker in brokers)
            {
                logger.Log("Querying broker: {0}", broker.Url);

                var status = new Messages.BrokerStatus {
                    BrokerId     = broker.Id,
                    UserId       = broker.UserId,
                    Url          = broker.Url,
                    SampledAtUtc = DateTime.UtcNow
                };

                try {
                    var part   = BuildBrokerUrl(broker.Url);
                    var client = new ManagementClient(part.HostPart, broker.Username, broker.Password, part.Port, true);

                    try {
                        var overview = client.GetOverview();
                        status.IsResponding    = true;
                        status.RabbitMQVersion = overview.ManagementVersion;

                        var connections = client.GetConnections();
                        var channels    = client.GetChannels();

                        foreach (var connection in connections)
                        {
                            var connectionMessage = new Messages.Connection {
                                Name = connection.Name
                            };
                            foreach (var property in connection.ClientProperties.PropertiesDictionary)
                            {
                                connectionMessage.ClientProperties.Add(new Messages.ClientProperty {
                                    Key   = property.Key,
                                    Value = property.Value.ToString()
                                });
                            }
                            AddConsumersToConnection(client, channels, connectionMessage);
                            status.GetOrCreateVHost(connection.Vhost).Connections.Add(connectionMessage);
                        }

                        AddQueuesToBroker(client, status);
                    } catch (Exception e) {
                        logger.Log("Exception in Harvester: {0}", e);
                        status.IsResponding = false;
                        status.ErrorMessage = string.Format("{0}: {1}", e.GetType().Name, e.Message);
                    }
                } catch (UrlParseException ex) {
                    logger.Log("UrlParseException in Harvester: {0}", ex);
                    status.IsResponding = false;
                    status.ErrorMessage = string.Format("{0}", ex.Message);
                }

                bus.Publish(status);
            }
        }