Esempio n. 1
0
        /// <summary>
        ///     Initialize a new instance of the SchemaRegistryClient class.
        /// </summary>
        /// <param name="config">
        ///     Configuration properties.
        /// </param>
        public CachedSchemaRegistryClient(IEnumerable <KeyValuePair <string, object> > config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config properties must be specified.");
            }

            var schemaRegistryUrisMaybe = config.Where(prop => prop.Key.ToLower() == SchemaRegistryUrlPropertyName).FirstOrDefault();

            if (schemaRegistryUrisMaybe.Value == null)
            {
                throw new ArgumentException("schema.registry.url configuration property must be specified.");
            }
            var schemaRegistryUris = (string)schemaRegistryUrisMaybe.Value;

            var timeoutMsMaybe = config.Where(prop => prop.Key.ToLower() == SchemaRegistryConnectionTimeoutMsPropertyName).FirstOrDefault();
            var timeoutMs      = timeoutMsMaybe.Value == null ? DefaultTimeout : (int)timeoutMsMaybe.Value;

            var identityMapCapacityMaybe = config.Where(prop => prop.Key.ToLower() == SchemaRegistryMaxCachedSchemasPropertyName).FirstOrDefault();

            this.identityMapCapacity = identityMapCapacityMaybe.Value == null ? DefaultMaxCachedSchemas : (int)identityMapCapacityMaybe.Value;

            var subjectNameStrategyMaybe = config.Where(prop => prop.Key.ToLower() == SchemaRegistrySubjectNameStrategyPropertyName).FirstOrDefault();

            this.subjectNameStrategy = subjectNameStrategyMaybe.Value == null ? SubjectNameStrategies.Default :
                                       SubjectNameStrategies.GetSubjectNameStrategy((string)subjectNameStrategyMaybe.Value);

            foreach (var property in config)
            {
                if (!property.Key.StartsWith("schema.registry."))
                {
                    continue;
                }

                if (property.Key != SchemaRegistryUrlPropertyName &&
                    property.Key != SchemaRegistryConnectionTimeoutMsPropertyName &&
                    property.Key != SchemaRegistryMaxCachedSchemasPropertyName &&
                    property.Key != SchemaRegistrySubjectNameStrategyPropertyName)
                {
                    throw new ArgumentException($"CachedSchemaRegistryClient: unexpected configuration parameter {property.Key}");
                }
            }

            this.restService = new RestService(schemaRegistryUris, timeoutMs);
        }
Esempio n. 2
0
 /// <summary>
 /// Allow other ISubjectNameStrategies to be used.
 /// </summary>
 /// <param name="name">The name used to look up the SubjectNameStrategy</param>
 /// <param name="strategy">The SubjectNameStrategy</param>
 public static void Register(string name, ISubjectNameStrategy strategy)
 {
     map.Add(name, strategy);
 }