private KafkaListenerConfiguration CreateConsumerConfiguration(KafkaTriggerAttribute attribute)
        {
            var consumerConfig = new KafkaListenerConfiguration()
            {
                BrokerList               = this.config.ResolveSecureSetting(nameResolver, attribute.BrokerList),
                ConsumerGroup            = this.nameResolver.ResolveWholeString(attribute.ConsumerGroup),
                Topic                    = this.nameResolver.ResolveWholeString(attribute.Topic),
                EventHubConnectionString = this.config.ResolveSecureSetting(nameResolver, attribute.EventHubConnectionString),
            };

            if (attribute.AuthenticationMode != BrokerAuthenticationMode.NotSet ||
                attribute.Protocol != BrokerProtocol.NotSet)
            {
                consumerConfig.SaslPassword           = this.config.ResolveSecureSetting(nameResolver, attribute.Password);
                consumerConfig.SaslUsername           = this.config.ResolveSecureSetting(nameResolver, attribute.Username);
                consumerConfig.SslKeyLocation         = this.config.ResolveSecureSetting(nameResolver, attribute.SslKeyLocation);
                consumerConfig.SslKeyPassword         = this.config.ResolveSecureSetting(nameResolver, attribute.SslKeyPassword);
                consumerConfig.SslCertificateLocation = this.config.ResolveSecureSetting(nameResolver, attribute.SslCertificateLocation);
                consumerConfig.SslCaLocation          = this.config.ResolveSecureSetting(nameResolver, attribute.SslCaLocation);

                if (attribute.AuthenticationMode != BrokerAuthenticationMode.NotSet)
                {
                    consumerConfig.SaslMechanism = (SaslMechanism)attribute.AuthenticationMode;
                }

                if (attribute.Protocol != BrokerProtocol.NotSet)
                {
                    consumerConfig.SecurityProtocol = (SecurityProtocol)attribute.Protocol;
                }
            }

            return(consumerConfig);
        }
コード例 #2
0
 public KafkaListener(
     ITriggeredFunctionExecutor executor,
     bool singleDispatch,
     KafkaOptions options,
     KafkaListenerConfiguration kafkaListenerConfiguration,
     object valueDeserializer,
     ILogger logger)
 {
     this.valueDeserializer     = valueDeserializer;
     this.executor              = executor;
     this.singleDispatch        = singleDispatch;
     this.options               = options;
     this.listenerConfiguration = kafkaListenerConfiguration;
     this.logger = logger;
     this.cancellationTokenSource = new CancellationTokenSource();
 }
        public static IListener CreateFor(KafkaTriggerAttribute attribute,
                                          Type parameterType,
                                          ITriggeredFunctionExecutor executor,
                                          bool singleDispatch,
                                          KafkaOptions options,
                                          KafkaListenerConfiguration consumerKafkaConfiguration,
                                          ILogger logger)
        {
            var valueType         = SerializationHelper.GetValueType(attribute.ValueType, attribute.AvroSchema, parameterType, out var avroSchema);
            var valueDeserializer = SerializationHelper.ResolveValueDeserializer(valueType, avroSchema);

            return((IListener)Activator.CreateInstance(
                       typeof(KafkaListener <,>).MakeGenericType(attribute.KeyType ?? typeof(Ignore), valueType),
                       new object[]
            {
                executor,
                singleDispatch,
                options,
                consumerKafkaConfiguration,
                valueDeserializer,
                logger
            }));
        }
コード例 #4
0
 public KafkaListener(
     ITriggeredFunctionExecutor executor,
     bool singleDispatch,
     KafkaOptions options,
     KafkaListenerConfiguration kafkaListenerConfiguration,
     bool requiresKey,
     IDeserializer <TValue> valueDeserializer,
     ILogger logger,
     string functionId)
 {
     this.ValueDeserializer     = valueDeserializer;
     this.executor              = executor;
     this.singleDispatch        = singleDispatch;
     this.options               = options;
     this.listenerConfiguration = kafkaListenerConfiguration;
     this.requiresKey           = requiresKey;
     this.logger = logger;
     this.cancellationTokenSource = new CancellationTokenSource();
     this.consumerGroup           = string.IsNullOrEmpty(this.listenerConfiguration.ConsumerGroup) ? "$Default" : this.listenerConfiguration.ConsumerGroup;
     this.topicName   = this.listenerConfiguration.Topic;
     this.functionId  = functionId;
     this.consumer    = new Lazy <IConsumer <TKey, TValue> >(() => CreateConsumer());
     this.topicScaler = new Lazy <KafkaTopicScaler <TKey, TValue> >(() => CreateTopicScaler());
 }
        private ITriggerBinding CreateBindingStrategy <TKey, TValue>(ParameterInfo parameter, KafkaListenerConfiguration listenerConfiguration, bool requiresKey, IDeserializer <TValue> valueDeserializer)
        {
            // TODO: reuse connections if they match with others in same function app
            Task <IListener> listenerCreator(ListenerFactoryContext factoryContext, bool singleDispatch)
            {
                var listener = new KafkaListener <TKey, TValue>(
                    factoryContext.Executor,
                    singleDispatch,
                    this.options.Value,
                    listenerConfiguration,
                    requiresKey,
                    valueDeserializer,
                    this.logger);

                return(Task.FromResult <IListener>(listener));
            }

            return(BindingFactory.GetTriggerBinding(new KafkaTriggerBindingStrategy <TKey, TValue>(), parameter, new KafkaEventDataConvertManager(this.converterManager, this.logger), listenerCreator));
        }
        ITriggerBinding CreateBindingStrategyFor(Type keyType, Type valueType, bool requiresKey, object valueDeserializer, ParameterInfo parameterInfo, KafkaListenerConfiguration listenerConfiguration)
        {
            var genericCreateBindingStrategy = this.GetType().GetMethod(nameof(CreateBindingStrategy), BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(keyType, valueType);

            return((ITriggerBinding)genericCreateBindingStrategy.Invoke(this, new object[] { parameterInfo, listenerConfiguration, requiresKey, valueDeserializer }));
        }