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

Reply via email to