コード例 #1
0
 /// <summary>
 /// Registers a middleware to serialize protobuf messages using schema registry
 /// </summary>
 /// <param name="middlewares">The middleware configuration builder</param>
 /// <param name="config">The json serializer configuration</param>
 /// <returns></returns>
 public static IProducerMiddlewareConfigurationBuilder AddSchemaRegistryProtobufSerializer(
     this IProducerMiddlewareConfigurationBuilder middlewares,
     ProtobufSerializerConfig config = null)
 {
     return(middlewares.AddSerializer(
                resolver => new ConfluentProtobufSerializer(resolver, config),
                resolver => new SchemaRegistryTypeResolver(new ConfluentProtobufTypeNameResolver(resolver.Resolve <ISchemaRegistryClient>()))));
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfluentProtobufSerializer"/> class.
        /// </summary>
        /// <param name="resolver">An instance of <see cref="IDependencyResolver"/></param>
        /// <param name="serializerConfig">An instance of <see cref="ProtobufSerializerConfig"/></param>
        public ConfluentProtobufSerializer(IDependencyResolver resolver, ProtobufSerializerConfig serializerConfig)
        {
            this.schemaRegistryClient =
                resolver.Resolve <ISchemaRegistryClient>() ??
                throw new InvalidOperationException(
                          $"No schema registry configuration was found. Set it using {nameof(ClusterConfigurationBuilderExtensions.WithSchemaRegistry)} on cluster configuration");

            this.serializerConfig = serializerConfig;
        }
コード例 #3
0
        internal ProtobufSerializerConfig GetSerializerConfig(ISchemaRegistryConfig config)
        {
            var c = new ProtobufSerializerConfig();

            if (config.AutoRegisterSchemas.HasValue)
            {
                c.AutoRegisterSchemas = config.AutoRegisterSchemas;
            }

            if (config.BufferBytes.HasValue)
            {
                c.BufferBytes = config.BufferBytes.Value;
            }

            if (config.UseDeprecatedFormat.HasValue)
            {
                c.UseDeprecatedFormat = config.UseDeprecatedFormat.Value;
            }

            if (config.SkipKnownTypes.HasValue)
            {
                c.SkipKnownTypes = config.SkipKnownTypes.Value;
            }

            if (config.SubjectNameStrategy.HasValue)
            {
                c.SubjectNameStrategy = (Confluent.SchemaRegistry.SubjectNameStrategy)config.SubjectNameStrategy.Value;
            }

            if (config.ReferenceSubjectNameStrategy.HasValue)
            {
                c.ReferenceSubjectNameStrategy = (Confluent.SchemaRegistry.ReferenceSubjectNameStrategy)config.ReferenceSubjectNameStrategy.Value;
            }

            if (config.UseLatestVersion.HasValue)
            {
                c.UseLatestVersion = config.UseLatestVersion.Value;
            }

            return(c);
        }