GH-422 GH-606 Add support for simplifying message headers to attribute mapping
Added CloudEventAttributesProvider and default implementation Added CloudEventMessageUtils
This commit is contained in:
@@ -20,8 +20,12 @@ import java.util.function.Function;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.function.cloudevent.CloudEventAttributes;
|
||||
import org.springframework.cloud.function.cloudevent.CloudEventAtttributesProvider;
|
||||
import org.springframework.cloud.function.cloudevent.DefaultCloudEventAttributesProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* Sample application that demonstrates how user functions can be triggered by cloud event.
|
||||
@@ -77,4 +81,38 @@ public class CloudeventDemoApplication {
|
||||
return v.toString();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Message<SpringReleaseEvent>, Message<SpringReleaseEvent>> consumeAndProduceCloudEvent(CloudEventAtttributesProvider ceAttrProvider) {
|
||||
return ceMessage -> {
|
||||
SpringReleaseEvent data = ceMessage.getPayload();
|
||||
data.setVersion("2.0");
|
||||
data.setReleaseDateAsString("01-10-2006");
|
||||
|
||||
CloudEventAttributes ceAttributes = ceAttrProvider.get(ceMessage.getHeaders())
|
||||
.setSource("https://interface21.icom/")
|
||||
.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();
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.spring.cloudevent;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -44,6 +45,15 @@ public class SpringReleaseEvent {
|
||||
this.releaseDate = releaseDate;
|
||||
}
|
||||
|
||||
public void setReleaseDateAsString(String releaseDate) {
|
||||
try {
|
||||
this.releaseDate = new SimpleDateFormat("dd-MM-yyyy").parse(releaseDate);
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getReleaseName() {
|
||||
return releaseName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user