Skip to content

Commit a9bb498

Browse files
committed
refactor: remove avro priming
1 parent 4423bfa commit a9bb498

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

powertools-kafka/src/main/java/software/amazon/lambda/powertools/kafka/PowertoolsSerializer.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,16 @@
1212
*/
1313
package software.amazon.lambda.powertools.kafka;
1414

15-
import java.io.ByteArrayOutputStream;
16-
import java.io.IOException;
1715
import java.io.InputStream;
1816
import java.io.OutputStream;
1917
import java.lang.reflect.ParameterizedType;
2018
import java.lang.reflect.Type;
21-
import java.util.Base64;
2219
import java.util.Map;
2320

2421
import com.amazonaws.services.lambda.runtime.CustomPojoSerializer;
2522
import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory;
2623
import com.amazonaws.services.lambda.runtime.events.KafkaEvent;
2724

28-
import org.apache.avro.Schema;
29-
import org.apache.avro.generic.GenericData;
30-
import org.apache.avro.generic.GenericDatumWriter;
31-
import org.apache.avro.generic.GenericRecord;
32-
import org.apache.avro.io.BinaryEncoder;
33-
import org.apache.avro.io.DatumWriter;
34-
import org.apache.avro.io.EncoderFactory;
3525
import org.apache.kafka.clients.consumer.ConsumerRecord;
3626
import org.apache.kafka.clients.consumer.ConsumerRecords;
3727
import org.crac.Context;
@@ -99,11 +89,6 @@ public void beforeCheckpoint(Context<? extends Resource> context) throws Excepti
9989
DeserializationUtils.determineDeserializationType();
10090

10191
jsonPriming();
102-
try {
103-
avroPriming();
104-
} catch (Exception e) {
105-
// Continue without any interruption if avro priming fails
106-
}
10792

10893
ClassPreLoader.preloadClasses();
10994
}
@@ -136,56 +121,6 @@ private void jsonPriming(){
136121
deserializers.fromJson(kafkaJson, consumerRecords);
137122
}
138123

139-
private void avroPriming() throws IOException {
140-
String avroSchema = "{\n" +
141-
" \"type\": \"record\",\n" +
142-
" \"name\": \"SimpleProduct\",\n" +
143-
" \"namespace\": \"software.amazon.lambda.powertools.kafka.test\",\n" +
144-
" \"fields\": [\n" +
145-
" {\"name\": \"id\", \"type\": \"string\"},\n" +
146-
" {\"name\": \"name\", \"type\": \"string\"},\n" +
147-
" {\"name\": \"price\", \"type\": [\"null\", \"double\"], \"default\": null}\n" +
148-
" ]\n" +
149-
"}";
150-
Schema schema = new Schema.Parser().parse(avroSchema);
151-
152-
// Create a GenericRecord
153-
GenericRecord avroRecord = new GenericData.Record(schema);
154-
avroRecord.put("id", "prime-topic-1");
155-
avroRecord.put("name", "Prime Product");
156-
avroRecord.put("price", 0.0);
157-
158-
// Create Kafka event JSON with avro data
159-
DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema);
160-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
161-
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(outputStream, null);
162-
datumWriter.write(avroRecord, encoder);
163-
byte[] avroBytes = outputStream.toByteArray();
164-
String base64Value = Base64.getEncoder().encodeToString(avroBytes);
165-
166-
String kafkaAvroJson = "{\n" +
167-
" \"eventSource\": \"aws:kafka\",\n" +
168-
" \"records\": {\n" +
169-
" \"prime-topic-1\": [\n" +
170-
" {\n" +
171-
" \"topic\": \"prime-topic-1\",\n" +
172-
" \"partition\": 0,\n" +
173-
" \"offset\": 0,\n" +
174-
" \"timestamp\": 1545084650987,\n" +
175-
" \"timestampType\": \"CREATE_TIME\",\n" +
176-
" \"key\": null,\n" +
177-
" \"value\": \"" + base64Value + "\",\n" +
178-
" \"headers\": []\n" +
179-
" }\n" +
180-
" ]\n" +
181-
" }\n" +
182-
"}";
183-
184-
Type records = createConsumerRecordsType(String.class, GenericRecord.class);
185-
PowertoolsDeserializer deserializers = DESERIALIZERS.get(DeserializationType.KAFKA_AVRO);
186-
deserializers.fromJson(kafkaAvroJson, records);
187-
}
188-
189124
private Type createConsumerRecordsType(Class<?> keyClass, Class<?> valueClass) {
190125
return new ParameterizedType() {
191126
@Override

0 commit comments

Comments
 (0)