GH-606 add initila support for generating default cloud event attributes
This commit is contained in:
@@ -90,29 +90,21 @@ public class CloudeventDemoApplication {
|
||||
data.setReleaseDateAsString("01-10-2006");
|
||||
|
||||
CloudEventAttributes ceAttributes = ceAttrProvider.get(ceMessage.getHeaders())
|
||||
.setSource("https://interface21.icom/")
|
||||
.setSource("https://interface21.com/")
|
||||
.setType("com.interface21");
|
||||
|
||||
return MessageBuilder.withPayload(data).copyHeaders(ceAttributes).build();
|
||||
};
|
||||
}
|
||||
|
||||
// // spring.io/applicationName
|
||||
//
|
||||
// @Bean
|
||||
// public Function<Message<SpringReleaseEvent>, SpringReleaseEvent> consumeAndProduceCloudEvent() {
|
||||
// return ceMessage -> {
|
||||
// SpringReleaseEvent data = ceMessage.getPayload();
|
||||
// data.setVersion("2.0");
|
||||
// data.setReleaseDateAsString("01-10-2006");
|
||||
//
|
||||
// CloudEventAtttributesProvider ceAttrProvider = new DefaultCloudEventAttributesProvider();
|
||||
//
|
||||
// CloudEventAttributes ceAttributes = ceAttrProvider.get(ceMessage.getHeaders())
|
||||
// .setSource("https://interface21.icom/")
|
||||
// .setType("com.interface21");
|
||||
//
|
||||
// return MessageBuilder.withPayload(data).copyHeaders(ceAttributes).build();
|
||||
// };
|
||||
// }
|
||||
@Bean
|
||||
public Function<Message<SpringReleaseEvent>, SpringReleaseEvent> consumeAndProduceCloudEventPojo() {
|
||||
return ceMessage -> {
|
||||
SpringReleaseEvent data = ceMessage.getPayload();
|
||||
data.setVersion("2.0");
|
||||
data.setReleaseDateAsString("01-10-2006");
|
||||
|
||||
return data;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,16 +50,16 @@ public class CloudeventDemoApplicationFunctionTests {
|
||||
* is (see `asPOJOMessage` and `asPOJO` specifically). Type conversion will happen
|
||||
* inside spring-cloud-function.
|
||||
*/
|
||||
Function<Message<String>, String> asPojoMessage = catalog.lookup("asPOJOMessage");
|
||||
Function<Message<String>, Message<String>> asPojoMessage = catalog.lookup("asPOJOMessage");
|
||||
System.out.println(asPojoMessage.apply(binaryCloudEventMessage));
|
||||
|
||||
Function<Message<String>, String> asPojo = catalog.lookup("asPOJO");
|
||||
Function<Message<String>, Message<String>> asPojo = catalog.lookup("asPOJO");
|
||||
System.out.println(asPojo.apply(binaryCloudEventMessage));
|
||||
|
||||
Function<Message<String>, String> asString = catalog.lookup("asString");
|
||||
Function<Message<String>, Message<String>> asString = catalog.lookup("asString");
|
||||
System.out.println(asString.apply(binaryCloudEventMessage));
|
||||
|
||||
Function<Message<String>, String> asStringMessage = catalog.lookup("asStringMessage");
|
||||
Function<Message<String>, Message<String>> asStringMessage = catalog.lookup("asStringMessage");
|
||||
System.out.println(asStringMessage.apply(binaryCloudEventMessage));
|
||||
}
|
||||
}
|
||||
@@ -83,4 +83,24 @@ public class CloudeventDemoApplicationFunctionTests {
|
||||
System.out.println(asPojoMessage.apply(binaryCloudEventMessage));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demoPureFunctionProduceConsumeCloudEventAsPojo() {
|
||||
try(ConfigurableApplicationContext context = SpringApplication.run(CloudeventDemoApplication.class)) {
|
||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||
CloudEventAtttributesProvider ceAttrProvider = new DefaultCloudEventAttributesProvider();
|
||||
Message<String> binaryCloudEventMessage = MessageBuilder
|
||||
.withPayload("{\"releaseDate\":\"24-03-2004\", \"releaseName\":\"Spring Framework\", \"version\":\"1.0\"}")
|
||||
.copyHeaders(ceAttrProvider.get("spring.io/spring-event", "com.example.springevent"))
|
||||
.build();
|
||||
|
||||
/*
|
||||
* NOTE how it makes no difference what the actual function signature
|
||||
* is (see `asPOJOMessage` and `asPOJO` specifically). Type conversion will happen
|
||||
* inside spring-cloud-function.
|
||||
*/
|
||||
Function<Message<String>, Message<String>> asPojoMessage = catalog.lookup("consumeAndProduceCloudEventPojo");
|
||||
System.out.println(asPojoMessage.apply(binaryCloudEventMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user