GH-422, GH-606 Fis structure mode attribute generation
This commit is contained in:
@@ -22,12 +22,9 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.function.cloudevent.CloudEventAttributes;
|
||||
import org.springframework.cloud.function.cloudevent.CloudEventAttributesProvider;
|
||||
import org.springframework.cloud.function.cloudevent.CloudEventMessageUtils;
|
||||
import org.springframework.cloud.function.web.util.HeaderUtils;
|
||||
@@ -37,7 +34,6 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* Sample application that demonstrates how user functions can be triggered by cloud event.
|
||||
@@ -55,6 +51,8 @@ import org.springframework.web.client.RestTemplate;
|
||||
@SpringBootApplication
|
||||
public class CloudeventDemoApplication {
|
||||
|
||||
boolean consumerSuccess;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(CloudeventDemoApplication.class, args);
|
||||
}
|
||||
@@ -145,22 +143,8 @@ public class CloudeventDemoApplication {
|
||||
Assert.notEmpty(idHeader, "'id' must not be null");
|
||||
List<String> specversionHeader = entity.getHeaders().get("ce-specversion");
|
||||
Assert.notEmpty(specversionHeader, "'specversion' must not be null");
|
||||
this.consumerSuccess = true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnExpression("'${K_SINK:}'!=''")
|
||||
public Consumer<Message<Map<String, Object>>> sink(CloudEventAttributesProvider provider,
|
||||
RestTemplateBuilder builder, @Value("${K_SINK}") String url) {
|
||||
RestTemplate client = builder.build();
|
||||
return eventMessage -> {
|
||||
RequestEntity<Map<String, Object>> entity = RequestEntity.post(URI.create("http://foo.com"))
|
||||
.headers(HeaderUtils.fromMessage(
|
||||
new MessageHeaders(CloudEventMessageUtils.generateAttributes(eventMessage, provider, "io.spring"))))
|
||||
.body(eventMessage.getPayload());
|
||||
client.exchange(entity, byte[].class);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user