Add transformer app for function sample

This commit is contained in:
Ilayaperumal Gopinathan
2020-07-23 19:36:31 +05:30
parent 06da4e8a7c
commit cee79f3c8d
13 changed files with 587 additions and 42 deletions

View File

@@ -50,26 +50,6 @@ public class HttpIngest {
};
}
@Bean
public Function<Message<?>, Message<?>> byteArrayToString() {
return message -> {
if (message.getPayload() instanceof byte[]) {
MessageHeaders headers = message.getHeaders();
String contentType = headers.containsKey("contentType") ?
headers.get("contentType").toString() :
"application/json";
if (contentType.contains("text") || contentType.contains("json") || contentType
.contains("x-spring-tuple")) {
message = MessageBuilder
.withPayload(new String((byte[]) ((byte[]) message.getPayload())))
.copyHeaders(message.getHeaders()).build();
}
}
return message;
};
}
public static void main(String[] args) {
SpringApplication.run(HttpIngest.class, args);
}

View File

@@ -8,7 +8,7 @@ spring.cloud.stream.kafka.binder.configuration.key:
spring.cloud.stream.kafka.binder.configuration.value:
serializer: org.apache.kafka.common.serialization.LongSerializer
spring.cloud.stream.function.definition: httpSupplier|byteArrayToLong;httpSupplier;
spring.cloud.stream.function.definition: httpSupplier|byteArrayToLong
spring.cloud.stream.function.bindings.httpSupplier|byteArrayToLong-out-0: clicks
spring.main.web-application-type: reactive