Closed stevenzwu closed 9 years ago
never mind. I think I can get the ephemeral port already. here is the java code snippet.
SQSRestServer sqsServer = SQSRestServerBuilder
.withInterface(hostname)
.withPort(port)
.start();
sqsServer.waitUntilStarted();
System.out.println("foo");
Try<Object> tryVal = sqsServer.startFuture().value().get();
if(tryVal.isSuccess()) {
Tcp.Bound bound = (Tcp.Bound) tryVal.get();
port = bound.localAddress().getPort();
System.out.println("port: " + bound.localAddress().getPort());
} else {
throw new RuntimeException("startup failed");
}
But my test still fail, because qetQueueUrl still returns port 9324. I will file a different issue for that problem.
Maybe you could post where port
comes from for future reference?
ElasticMQ can be an excellent choice for in-memory SQS replacement for unit test. For testing, I don't want to specify a specific/static port number. I would rather let system pick a ephemeral port number when passing port number zero to SQSRestServerBuilder. This way, I can avoid potential port number conflict.
But I would need SQSRestServer to expose the actual ephemeral port bound by http server listener, so that I can construct the proper endpoint for SQS client.