-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spring webflux + serverless #239
Comments
I have not tested with WebFlux. I will mark this as a feature request and look into it for the next minor release. |
Hi, is there any feedback on this? @sapessi was the webflux support added at some point to any release? Thanks in advance |
Hi @renecairo - I have not worked on Webflux yet. I'm assuming you have tested with the latest version of this library? The error indicates that it cannot load |
Hi @sapessi We are building fully reactive micro-services using Spring Boot 2.x and Webflux with Reactor Netty (non-servlet). Spring web-mvc is the one including the missing class and we can't have both dependencies in the same project. |
Would like to comment that we've experience the same thing. It seems |
I spent some time looking into this. I see two possible path forward:
To be clear, AWS Lambda itself enforces that each sandbox only processes one event at a time. So you won't see any performance gain by using the reactor API. Adding support for this in the library simply gives you the ability to port your code between compute platforms. Do you use any other framework for "reactor" development other than Spring @jayasai470, @renecairo, @khakiout? |
@sapessi right now no. |
@sapessi At the moment no, we only use 'reactor' with Spring.
We'll take note of this. If Serverless doesn't benefit much from Reactor maybe we can go back to the usual way. |
I'd say it's still worth testing @khakiout, especially if your function performs multiple, network-bound operations all at once. I'm hoping to find some time to work on this soon.
|
…port WebFlux and reactive embedded servers for Spring to address #239
…d debug System.out calls (#239 contd)
…mbedded servers, actually addressing #239.
Hey @jayasai470, @renecairo, @khakiout - this was a deep rabbit hole and I ended up refactoring most of the servlet context and spring integration. The first experimental version of the changes are in the
|
Hey @jayasai470, @renecairo, @khakiout did you ever get a chance to test this? I want to push out release 1.4 soon and I'd like to have a few more eyes on the new integration. |
Hi @sapessi , I have tested this release in my Demo project for spring-webflux and it worked fine. Thanks a lot for your guys work. |
Thanks for the help @zorrofox, really appreciated! |
Checking on this now. |
@sapessi thanks for the work, i have made a sample project here for testing |
Weird @jayasai470, I cloned your repo and added a new unit test to run a full request through, the response looks correct to me: @Test
public void testRequest() throws IOException {
LambdaHandler h = new LambdaHandler();
AwsProxyRequest req = new AwsProxyRequestBuilder("/api/status", "GET").build();
ByteArrayOutputStream os = new ByteArrayOutputStream();
h.handleRequest(
new ByteArrayInputStream(LambdaContainerHandler.getObjectMapper().writeValueAsBytes(req)),
os,
new MockLambdaContext()
);
AwsProxyResponse resp = LambdaContainerHandler.getObjectMapper().readValue(os.toByteArray(), AwsProxyResponse.class);
assertEquals(200, resp.getStatusCode());
System.out.println("Body: " + resp.getBody());
assertEquals("status is up", resp.getBody());
} Are you getting an actual exception? |
the router function "/api/status" and "/api/time" works fine both in local and aws but spring cloud function ("/hello") does not send any resp in aws. If we run the app in local and do a curl -x POST http://localhost:8080/hello -d "somestring" i am getting proper response like "SOMESTRING". But when we deploy to aws lambda and api gateway(sls deploy) i am not receiving any output. |
Thanks for the clarification. I'll test this today. |
I spent some time looking into this @jayasai470, looks like Functions use a fairly different interface from the standard http APIs. I believe it would require building a fully reactive handler for the framework. It is something I plan to look into but not for the 1.4 release - I'll open a separate issue to track this. In the meanwhile, I would recommend using Spring's own adapter. |
@sapessi yup i think spring cloud function with aws adapaters is good enough if we have one function, but if any one wants to have a spring web or webflux integration for http end points then this is good enough Thanks for the hard work and quick support. |
@sapessi i have tried the 1.4 version creating a simple rest api using spring boot 2.1.8 with webflux, but i get the same blank body output mentioned by @jayasai470 from my endpoint. Calling the api using the netty embedded server works fine, retrieving the body data. |
@cesardrk you are using the |
@sapessi yes, i'm using the springboot2 package. |
I have created an ElasticSearch client using RestHighLevelClient, with a simple get endpoint to retrieve all nearby places using geolocation. This is my endpoint:
and this is my repository class:
And my test class which fails:
|
@sapessi should i open a new issue with the above example? |
@cesardrk Let me have a play with the sample code to see if I can root-cause the issue. I'll open a separate issue if it's needed. Is your |
@sapessi yes, i have used your sample as a starting point. The handler actually is almost identical, i just removed the cognito filter. |
Thanks @cesardrk - I hope to test with this code tomorrow. Any chance you can also share the execution log from CloudWatch? Just in case something jumps out at me. |
@sapessi i did not see any useful information from the logs. But i could upload then if u want. Anyway, i just uploaded an example project in github, replacing the elasticsearch client with an mocked completable future call (with a 5s sleep), that reproduces the issue im having: https://github.com/cesardrk/aws-serverless-java-container-webflux |
Quick update @cesardrk. I've managed to replicate the issue in my tests. Looks like when you use a future object either the return Flux.create((sink) -> {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
sink.next(MESSAGE);
}); However, when I test your method with SpringBoot's embedded container it seems to work fine. With suggests there is an issue in the response flushing logic on our side. Let me dig deeper into this today. |
Another update. It does indeed look like it has something to do in how we release the latch in the response object. At the moment, we release it when the flush method is called on the output stream. This decision was driven by the fact that, from Lambda, we need to return the full output of the response at once - we don't get to "stream" response data. I'll open a separate issue to track this and investigate how I we can find a good middle-ground. |
I made the lambda start, but the application context is not created correctly becasue it instanciates a webflux bean. It looks like netty does not play well with aws lambda. hmm relevant links: aws/serverless-java-container#239
Scenario
just wanted to check if there is a support for spring webflux without server sent events ?
Expected behavior
Actual behavior
Steps to reproduce
Full log output
The text was updated successfully, but these errors were encountered: