I stumbled upon :)

https://camel.apache.org/components/3.14.x/others/main.html

It says - Its recommended to migrate to use fast type converter
loading by setting Converter(loader = true) on your custom type
converter classes.

I couldn't make the original method work - but it does work with
@Converter(generateLoader = true), and running mvn package.




ચિરાગ/चिराग/Chirag
------------------------------------------
Sent from My Gmail Account

On Thu, Jan 27, 2022 at 12:58 PM Chirag <[email protected]> wrote:
>
> It doesn't seem to be helping.
> Let me do some digging.
>
> ચિરાગ/चिराग/Chirag
> ------------------------------------------
> Sent from My Gmail Account
>
> On Thu, Jan 27, 2022 at 3:16 AM Claus Ibsen <[email protected]> wrote:
> >
> > Hi
> >
> > Ah yeah there is no classpath annotation scanning like you can have
> > with spring boot / quarkus.
> >
> > However for loading custom type converters where you have that file in
> > the classpath, then you can try setting
> > camel.main.loadTypeConverters=true
> >
> >
> > On Thu, Jan 27, 2022 at 5:37 AM Chirag <[email protected]> wrote:
> > >
> > > I am trying out following
> > > https://camel.apache.org/blog/2020/05/CdcWithCamelAndDebezium/
> > >
> > > with few changes:
> > > 1. Using MySQL
> > > 2. Trying to use a TypeConverter
> > >
> > > I have created a class called Customer - Here is snippet:
> > >
> > > public class Customer {
> > >     public long getId() {
> > >         return id;
> > >     }
> > >
> > >     public void setId(long id) {
> > >         this.id = id;
> > >     }
> > >
> > >     public String getFirst_name() {
> > >         return first_name;
> > >     }
> > >
> > > With that - Created a TypeConverter class with a method as below.
> > >
> > > @Converter
> > > public static Customer toCustomer(final Struct struct) {
> > >     logger.debug("toCustomer");
> > >     return new Customer(struct.getInt64("ID"),
> > > struct.getString("FIRST_NAME"),struct.getString("LAST_NAME"),
> > > struct.getString("EMAIL"));
> > > }
> > >
> > > The class is listed in
> > > Project\src\main\resources\META-INF\services\org\apache\camel\TypeConverter
> > >  file
> > >
> > > Following fails:
> > >
> > > from("debezium-mysql:mydb....).convertBodyTo(Customer.class)
> > > .marshal().json(JsonLibrary.Gson)
> > > .to("file:/Folder/SomeData");
> > >
> > > Following Works:
> > > from("debezium-mysql:mydb....).convertBodyTo(Map.class)
> > > .marshal().json(JsonLibrary.Gson)
> > > .to("file:/Folder/SomeData");
> > >
> > > With Map.class my understanding is that it invokes -
> > > debeziumtypeconverter and works fine.
> > >
> > > Similarly - I want to invoke My Customerl.class.
> > >
> > > org.apache.camel.InvalidPayloadException: No body available of type:
> > > com.company.Customer but has value:
> > > Struct{ID=1,FIRST_NAME=MyName,LAST_NAME=MyLastName,[email protected]}
> > > of type: org.apache.kafka.connect.data.Struct on: Message.
> > > Caused by: No type converter available to convert from type:
> > > org.apache.kafka.connect.data.Struct to the required type:
> > > com.company.Customer with value
> > > Struct{ID=1,FIRST_NAME=MyName,LAST_NAME=MyLastName,[email protected]}.
> > > Exchange[0EDB7CF530EA352-0000000000000001].
> > > Caused by: [org.apache.camel.NoTypeConversionAvailableException - No
> > > type converter available to convert from type:
> > > org.apache.kafka.connect.data.Struct to the required type:
> > > com.company.Customer with value
> > > Struct{ID=1,FIRST_NAME=MyName,LAST_NAME=MyLastName,[email protected]}]
> > > at 
> > > org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:125)
> > > at 
> > > org.apache.camel.support.processor.ConvertBodyProcessor.process(ConvertBodyProcessor.java:118)
> > > at org.apache.camel.support.processor.ConvertBodyProcessor.proce
> > >
> > > Question:
> > > 1. Does Camel-Main support Annotation and the ability to register
> > > TypeConverter automatically?
> > > 2. I see a slightly different way of defining  TypeConverter
> > > https://github.com/debezium/debezium-examples/blob/main/camel-component/qa-camel/src/main/java/io/debezium/examples/camel/pipeline/Converters.java
> > > - but this doesn't even seem to use META-INF  or a registry - so not
> > > sure how it would work.
> > >
> > > ચિરાગ/चिराग/Chirag
> > > ------------------------------------------
> > > Sent from My Gmail Account
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to