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,28 @@
package io.spring.cloudevent;
import java.util.function.Consumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.cloudevent.CloudEventMessageBuilder;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public Consumer<Person> hire(StreamBridge streamBridge) {
return person -> {
Employee employee = new Employee(person);
streamBridge.send("hire-out-0", CloudEventMessageBuilder.withData(employee)
.setSource("http://spring.io/rsocket")
.setId("1234567890")
.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;
}
}