Add stream (kafka, Rabbit) and Rsocket examples for Cloud Event

This commit is contained in:
Oleg Zhurakousky
2020-12-18 16:33:48 +01:00
parent 17d5d4b727
commit 8ece3d3083
41 changed files with 2277 additions and 163 deletions

View File

@@ -0,0 +1,47 @@
package io.spring.cloudevent;
import java.net.URI;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.cloudevent.CloudEventHeaderEnricher;
import org.springframework.cloud.function.cloudevent.CloudEventMessageBuilder;
import org.springframework.cloud.function.cloudevent.CloudEventMessageUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public Function<Person, Employee> hire() {
return person -> {
Employee employee = new Employee(person);
return employee;
};
}
// uncomment while keeping the above POJO function
// @Bean
// public CloudEventHeaderEnricher cloudEventEnricher() {
// return messageBuilder -> messageBuilder.setSource("http://spring.io/cloudevent")
// .setType("sample").setId("987654");
// }
// uncomment while commenting the previous two beans
// @Bean
// public Function<Message<Person>, Message<Employee>> hire() {
// return message -> {
// Person person = message.getPayload();
// Employee employee = new Employee(person);
// return CloudEventMessageBuilder.withData(employee).setId("123456")
// .setSource(URI.create("https://spring.cloudevenets.sample")).build();
// };
// }
}

View File

@@ -0,0 +1,41 @@
package io.spring.cloudevent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class Employee {
private Person person;
private int id;
public Employee() {
}
public Employee(Person person) {
this.person = person;
this.id = new Random().nextInt(1000);
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMessage() {
return "Employee " + id + " was hired on " + new SimpleDateFormat("dd-MM-yyyy").format(new Date());
}
}

View File

@@ -0,0 +1,24 @@
package io.spring.cloudevent;
public class Person {
private String firstName;
private String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}

View File

@@ -0,0 +1,3 @@
spring.cloud.function.definition=hire
spring.cloud.stream.bindings.hire-in-0.binder=rabbit
spring.cloud.stream.bindings.hire-out-0.binder=kafka