mirror of
https://github.com/wahyd4/spring-cloud-stream-samples.git
synced 2026-08-26 05:55:54 +10:00
New sample for Kafka native serialization with functions
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
package com.example.kafkanativeserialization;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class KafkaNativeSerializationApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(KafkaNativeSerializationApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, Person> process() {
|
||||
return str -> {
|
||||
Person item = new Person(str);
|
||||
return item;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.example.kafkanativeserialization;
|
||||
|
||||
import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||
|
||||
public class MyJsonDeserializer extends JsonDeserializer<Person> {
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.example.kafkanativeserialization;
|
||||
|
||||
import org.apache.kafka.common.header.Headers;
|
||||
import org.springframework.kafka.support.serializer.JsonSerializer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
public class MyJsonSerializer extends JsonSerializer<Object> {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public byte[] serialize(String topic, Headers headers, @Nullable Object data) {
|
||||
return super.serialize(topic, headers, data);
|
||||
}
|
||||
@Override
|
||||
@Nullable
|
||||
public byte[] serialize(String topic, @Nullable Object data) {
|
||||
return super.serialize(topic, data);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.example.kafkanativeserialization;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String name;
|
||||
public Person() {
|
||||
}
|
||||
public Person(String name) {
|
||||
this.setName(name);
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user