Add transformer app for function sample
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user