Skip to content

Instantly share code, notes, and snippets.

@bytekast
Created March 28, 2017 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytekast/dbea94d14ea41084a2143b569d7cab0e to your computer and use it in GitHub Desktop.
Save bytekast/dbea94d14ea41084a2143b569d7cab0e to your computer and use it in GitHub Desktop.
@SpringBootApplication
@ComponentScan
@Log4j
class VertxLambdaHandler implements RequestHandler<Map, Response> {
static void main(String[] args) throws Exception {
LambdaHandler.newInstance().getApplicationContext(args)
}
@Memoized
ApplicationContext getApplicationContext(String[] args = []) {
return SpringApplication.run(LambdaHandler.class, args)
}
@Override
Response handleRequest(Map input, Context context) {
final Request request = new Request(context.awsRequestId, input)
def eventBus = applicationContext.getBean(EventBus.class)
CompletableFuture<Response> future = new CompletableFuture<>()
eventBus.send(request.methodResource(), request, { ar ->
if (ar.succeeded()) {
assert ar.result().body() instanceof Response
log.info "Received reply: ${ar.result().body()}"
future.complete(ar.result().body())
}
})
future.get(5, TimeUnit.SECONDS)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment