示例#1
0
        private void ValidateConnection(string correlationId, ConnectionParams connection)
        {
            if (connection == null)
            {
                throw new ConfigException(correlationId, "NO_CONNECTION", "NATS connection is not set");
            }

            var uri = connection.Uri;

            if (!string.IsNullOrEmpty(uri))
            {
                return;
            }

            var protocol = connection.GetProtocolWithDefault("nats");

            if (string.IsNullOrEmpty(protocol))
            {
                throw new ConfigException(correlationId, "NO_PROTOCOL", "Connection protocol is not set");
            }
            if (protocol != "nats")
            {
                throw new ConfigException(correlationId, "UNSUPPORTED_PROTOCOL", "The protocol " + protocol + " is not supported");
            }

            var host = connection.Host;

            if (string.IsNullOrEmpty(host))
            {
                throw new ConfigException(correlationId, "NO_HOST", "Connection host is not set");
            }

            var port = connection.GetAsIntegerWithDefault("port", 1883);

            if (port == 0)
            {
                throw new ConfigException(correlationId, "NO_PORT", "Connection port is not set");
            }

            return;
        }