sdk-java/examples/spring-rsocket
github-actions[bot] b9eaa2fcaa
Bump to 2.5.0-SNAPSHOT (#474)
Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: pierDipi <pierdipi@redhat.com>
2022-09-06 15:52:34 +02:00
..
src Add support for RSockets with Spring (#349) 2021-03-05 09:18:19 +01:00
README.md Add support for RSockets with Spring (#349) 2021-03-05 09:18:19 +01:00
pom.xml Bump to 2.5.0-SNAPSHOT (#474) 2022-09-06 15:52:34 +02:00

README.md

Spring RSockets + CloudEvents sample

Build

mvn package

Start Server

mvn spring-boot:run

You can try sending a request using rsc, and it echos back a cloud event the same body and with new ce-* headers:

rsc --request --dataMimeType=application/cloudevents+json --route=event \
    --data='{"data": {"value": "Foo"},
           "id": "1", 
           "source": "cloud-event-example", 
           "type": "my.application.Foo", 
           "specversion": "1.0"}' \
    --debug tcp://localhost:7000

The event endpoint is implemented like this (the request and response are modelled directly as a CloudEvent):

@MessageMapping("event")
public Mono<CloudEvent> event(@RequestBody Mono<CloudEvent> body) {
	return ...;
}

and to make that work we need to install the codecs:

@Bean
@Order(-1)
public RSocketStrategiesCustomizer cloudEventsCustomizer() {
	return new RSocketStrategiesCustomizer() {
		@Override
		public void customize(Builder strategies) {
			strategies.encoder(new CloudEventEncoder());
			strategies.decoder(new CloudEventDecoder());
		}
	};

}