bclozel / spring-flights Goto Github PK
View Code? Open in Web Editor NEWDemo application showcasing RSocket support in Spring
Demo application showcasing RSocket support in Spring
I am trying to replicate the logic you used to update all connected clients using rsocket-js as the client and spring boot starter rsocket as the server... I cannot seem to do it. I replicated your exact configuration from this project. All my Server -> Client(s) calls are ignored and/or fail silently... not sure where the error is in the stack nor can I find another example on the web that demonstrates how to make calls from Spring boot rsocket server -> rsocket-js client other than this one. I have a few questions:
Does the rsocket-js client responder need any additional configuration to the rsocket-js client (or spring boot rsocket starter server) other than passing in a responder: new ResponderHandler(...)
during rsocket-js client initialization? Any advice on how to troubleshoot further would be greatly appreciated.
responder logic for rsocket-js
class ResponderHandler{
fireAndForget(payload) {
if(payload.metadata.get(Metadata.ROUTE) == "my-message") {
const p = payload.data;
//do something, anything!, complain about metadataType... just don't fail silently :(
}
}
}
Calling this method inside the controller
private Mono<Void> testFirstAndForget(RSocketRequester requester) {
Map<String, String> metadata = Collections.singletonMap("route", "my-message");
return requester.metadata(metadata, JsonMetadataStrategiesCustomizer.METADATA_MIME_TYPE).data("test").send();
}
Custom JsonMetadataStraegiesCustomizer
@Component
public class JsonMetadataStrategiesCustomizer implements RSocketStrategiesCustomizer {
public static final MimeType METADATA_MIME_TYPE = MimeType.valueOf("application/vnd.spring.rsocket.metadata+json");
private static final ParameterizedTypeReference<Map<String, String>> METADATA_TYPE =
new ParameterizedTypeReference<Map<String, String>>() {};
@Override
public void customize(RSocketStrategies.Builder strategies) {
strategies.metadataExtractorRegistry(registry -> {
registry.metadataToExtract(METADATA_MIME_TYPE, METADATA_TYPE, (in, map) -> {
map.putAll(in);
});
});
}
}
We've introduced a temporary workaround in eb8ad0a to manually encode the routing metadata with the expected format.
Once the rsocket-js library has been updated to support composite metadata, we should be able to undo that workaround and possibly add other metadata, such as security-related information.
Due to RSocket metadata changes, the current rsocket-cli version (1.15.0) is out of date and calls result with:
java.lang.IndexOutOfBoundsException: readerIndex(1) + length(108) exceeds writerIndex(20): AbstractPooledDerivedByteBuf$PooledNonRetainedSlicedByteBuf(ridx: 1, widx: 20, cap: 20/20, unwrapped: PooledUnsafeDirectByteBuf(ridx: 128, widx: 128, cap: 1024))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1451)
Hi Brian
Many thanks for the sample project - very helpful in learning how to use RSockets.
How do I add CORS configuration - lets say to the Radars Controller to restrict the requests to come from an allowed origins ?
I tried @CrossOrigin
and it does not work and I also tried adding the following but does not work. If RSocket via websockets doesnt support CORS configuration then it would be harder for security sensitive applications from adopting rsocket.
@Bean
CorsConfigurationSource corsConfiguration() {
CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.applyPermitDefaultValues();
corsConfig.addAllowedMethod(HttpMethod.PUT);
corsConfig.addAllowedMethod(HttpMethod.DELETE);
corsConfig.setAllowedOrigins(Arrays.asList(FRONTEND_LOCALHOST, FRONTEND_STAGING));
UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig);
return source;
}
@Bean
CorsWebFilter corsWebFilter() {
CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowedOrigins(Arrays.asList("http://allowed-origin.com"));
corsConfig.setMaxAge(8000L);
corsConfig.addAllowedMethod("PUT");
corsConfig.addAllowedHeader("Baeldung-Allowed");
UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig);
return new CorsWebFilter(source);
}
Where is the main.js file
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.