Created
March 28, 2017 04:07
-
-
Save bytekast/dbea94d14ea41084a2143b569d7cab0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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