GH-731 Add support for SDK CloudEvent type
The type itself comes form cloud event sdk. And while s-c-function provides native support for cloud events, this is necessary for cases when user uses CloudEvent type in the signature of a function Resolves #731
This commit is contained in:
@@ -98,6 +98,12 @@
|
||||
<version>${avro.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-spring</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -234,6 +234,9 @@ public final class CloudEventMessageUtils {
|
||||
static Message<?> toCanonical(Message<?> inputMessage, MessageConverter messageConverter) {
|
||||
Map<String, Object> headers = (Map<String, Object>) ReflectionUtils.getField(MESSAGE_HEADERS, inputMessage.getHeaders());
|
||||
canonicalizeHeaders(headers, false);
|
||||
if (isCloudEvent(inputMessage) && headers.containsKey("content-type")) {
|
||||
inputMessage = MessageBuilder.fromMessage(inputMessage).setHeader(MessageHeaders.CONTENT_TYPE, headers.get("content-type")).build();
|
||||
}
|
||||
|
||||
String inputContentType = (String) inputMessage.getHeaders().get(DATACONTENTTYPE);
|
||||
// first check the obvious and see if content-type is `cloudevents`
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import io.cloudevents.spring.messaging.CloudEventMessageConverter;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
@@ -142,6 +143,13 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
return new AvroSchemaMessageConverter(new AvroSchemaServiceManagerImpl());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnClass(name = "io.cloudevents.spring.messaging.CloudEventMessageConverter")
|
||||
public MessageConverter cloudEventMessageConverter() {
|
||||
return new CloudEventMessageConverter();
|
||||
}
|
||||
|
||||
@Bean(RoutingFunction.FUNCTION_NAME)
|
||||
RoutingFunction functionRouter(FunctionCatalog functionCatalog, FunctionProperties functionProperties,
|
||||
BeanFactory beanFactory, @Nullable MessageRoutingCallback routingCallback) {
|
||||
|
||||
Reference in New Issue
Block a user