Skip to content
Advertisement

KafkaException: class is not an instance of org.apache.kafka.common.serialization.Deserializer

I want to implement Kafka producer which sends and receives Java Serialized Objects. I tried this:

Producer:

JavaScript

}

Send object:

JavaScript

Consumer:

JavaScript

// Receive Object

JavaScript

When I deploy the Producer I get error during deployment:

Caused by: org.apache.kafka.common.KafkaException: class org.engine.plugin.transactions.factory.SaleResponseFactory is not an instance of org.apache.kafka.common.serialization.Deserializer

Custom object

JavaScript

import org.apache.kafka.common.serialization.Deserializer; @Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder(toBuilder = true) public class SaleResponseFactory implements Serializable, Deserializer { private static final long serialVersionUID = 1744050117179344127L; private String unique_id; @Override public Object deserialize(String s, byte[] bytes) { return null; } }

Do you know how I can fix this issue?

EDIT: I tried this:

Producer:

JavaScript

}

Send object:

JavaScript

Consumer:

JavaScript

// Receive Object

JavaScript

Custom objects

JavaScript

When I try to send message I get error:

JavaScript

Do you know how I can fix this issue?

EDIT: I managed to implement these improvements:

Producer:

JavaScript

}

Send object:

JavaScript

Consumer:

JavaScript

Receive Object

JavaScript

Custom objects

JavaScript

When I send some message I get error:

JavaScript

Do you know how I can solve this issue?

Advertisement

Answer

You are using different type to cast the object than what it was serialize with. Not sure why you need to do that. You can update your deserialize to something like below.

JavaScript
JavaScript

This also means your serialization didn’t work as expected. Make sure you have valid payload before you try to cast.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement