0

i am using camel 2.25 , due to some reason i am unable to upgrade to higher version, i need to add avro serialization support, the avro serialization properties can be set in camel 3.x version in additional properties, but in 2.25 support is not provided ,as a workaround i am using enhancer class which can intercept createProducerProperties of org.apache.camel.component.kafka.KafkaConfiguration.class and add the kafka avro serializer properties at runtime ,and these properties can be different for each producer so need to send it differently at startup, but the callback class is never being called

Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(org.apache.camel.component.kafka.KafkaConfiguration.class);
        enhancer.setCallback((MethodInterceptor) (obj, method, v1, proxy) -> {
            if (method.getDeclaringClass() != Object.class && method.getName().equals("createProducerProperties")) {

                Properties s= (Properties) proxy.invokeSuper(obj, v1);
                s.put(KafkaAvroSerializerConfig.AUTO_REGISTER_SCHEMAS, false);
                s.put(KafkaAvroSerializerConfig.KEY_SUBJECT_NAME_STRATEGY,keySubjectNamingStrategy);
                s.put(KafkaAvroSerializerConfig.VALUE_SUBJECT_NAME_STRATEGY,valueSubjectNamingStrategy);
                s.put(AbstractKafkaSchemaSerDeConfig.BEARER_AUTH_CREDENTIALS_SOURCE, "TOKEN");
                s.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,keySerializerClass);
                s.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,valueSerializerClass);
                return s;
            } else{
                return proxy.invokeSuper(obj, v1);
            }
        }); 

i looked over How to use camel-avro-consumer & producer?, but properties are static but i need to set the properties dynamically for different client like recordnamingstrategy , serailizer etc for different producer client which are created during service startup

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
triples13
  • 206
  • 4
  • 18

0 Answers0