Skip to content

Commit a04e2cc

Browse files
committed
0.12.0 release
1 parent a2d4686 commit a04e2cc

File tree

6 files changed

+51
-27
lines changed

6 files changed

+51
-27
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tl;dr
55
-----
66

77
* message queue system
8-
* runs stand-alone ([download](https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.11.1.jar)) or embedded
8+
* runs stand-alone ([download](https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.12.0.jar)) or embedded
99
* [Amazon SQS](http://aws.amazon.com/sqs/)-compatible interface
1010
* fully asynchronous implementation, no blocking calls
1111

@@ -43,18 +43,18 @@ Installation: stand-alone
4343
-------------------------
4444

4545
You can download the stand-alone distribution here:
46-
[https://s3/.../elasticmq-server-0.11.1.jar](https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.11.1.jar)
46+
[https://s3/.../elasticmq-server-0.12.0.jar](https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.12.0.jar)
4747

4848
Java 6 or above is required for running the server.
4949

5050
Simply run the jar and you should get a working server, which binds to `localhost:9324`:
5151

52-
java -jar elasticmq-server-0.11.1.jar
52+
java -jar elasticmq-server-0.12.0.jar
5353

5454
ElasticMQ uses [Typesafe Config](https://github.com/typesafehub/config) for configuration. To specify custom
5555
configuration values, create a file (e.g. `custom.conf`), fill it in with the desired values, and pass it to the server:
5656

57-
java -Dconfig.file=custom.conf -jar elasticmq-server-0.11.1.jar
57+
java -Dconfig.file=custom.conf -jar elasticmq-server-0.12.0.jar
5858

5959
The config file may contain any configuration for Akka and ElasticMQ. Current ElasticMQ configuration values are:
6060

@@ -78,6 +78,10 @@ rest-sqs {
7878
sqs-limits = strict
7979
}
8080
81+
// Should the node-address be generated from the bind port/hostname
82+
// Set this to true e.g. when assigning port automatically by using port 0.
83+
generate-node-address = false
84+
8185
queues {
8286
// See next section
8387
}
@@ -87,7 +91,7 @@ You can also provide an alternative [Logback](http://logback.qos.ch/) configurat
8791
[default](server/src/main/resources/logback.xml) is configured to
8892
log INFO logs and above to the console):
8993

90-
java -Dlogback.configurationFile=my_logback.xml -jar elasticmq-server-0.11.1.jar
94+
java -Dlogback.configurationFile=my_logback.xml -jar elasticmq-server-0.12.0.jar
9195

9296
How are queue URLs created
9397
--------------------------
@@ -98,12 +102,14 @@ To customize, you should properly set the protocol/host/port/context in the `nod
98102
You can also set `node-address.host` to a special value, `"*"`, which will cause any queue URLs created during a request
99103
to use the path of the incoming request. This might be useful e.g. in containerized (Docker) deployments.
100104

101-
Note that changing the `bind-port` and `bind-hostname` settings does not affect the queue URLs in any way.
102-
105+
Note that changing the `bind-port` and `bind-hostname` settings does not affect the queue URLs in any way unless
106+
`generate-node-address` is `true`. In that case, the bind host/port are used to create the node address. This is
107+
useful when the port should be automatically assigned (use port `0` in such case, the selected port will be
108+
visible in the logs).
103109
Automatically creating queues on startup
104110
----------------------------------------
105111

106-
Queues can be automatically created on startup by providing appropriate configuration (since 0.9.3):
112+
Queues can be automatically created on startup by providing appropriate configuration:
107113

108114
The queues are specified in a custom configuration file. For example, create a `custom.conf` file with the following:
109115

@@ -182,15 +188,15 @@ ElasticMQ dependencies in SBT
182188
-----------------------------
183189

184190
// Scala 2.11
185-
val elasticmqSqs = "org.elasticmq" %% "elasticmq-rest-sqs" % "0.11.1"
191+
val elasticmqSqs = "org.elasticmq" %% "elasticmq-rest-sqs" % "0.12.0"
186192

187193
// Scala 2.10
188194
val elasticmqSqs = "org.elasticmq" %% "elasticmq-rest-sqs" % "0.7.1"
189195

190196
If you don't want the SQS interface, but just use the actors directly, you can add a dependency only to the `core`
191197
module:
192198

193-
val elasticmqCore = "org.elasticmq" %% "elasticmq-core" % "0.11.1"
199+
val elasticmqCore = "org.elasticmq" %% "elasticmq-core" % "0.12.0"
194200

195201
If you want to use a snapshot version, you will need to add the [https://oss.sonatype.org/content/repositories/snapshots/](https://oss.sonatype.org/content/repositories/snapshots/) repository to your configuration.
196202

@@ -202,7 +208,7 @@ Dependencies:
202208
<dependency>
203209
<groupId>org.elasticmq</groupId>
204210
<artifactId>elasticmq-rest-sqs_2.11</artifactId>
205-
<version>0.11.1</version>
211+
<version>0.12.0</version>
206212
</dependency>
207213

208214
If you want to use a snapshot version, you will need to add the [https://oss.sonatype.org/content/repositories/snapshots/](https://oss.sonatype.org/content/repositories/snapshots/) repository to your configuration.
@@ -216,9 +222,9 @@ have been discontinued.
216222
Current versions
217223
----------------
218224

219-
*Stable*: 0.11.1, 0.8.12
225+
*Stable*: 0.12.0, 0.8.12
220226

221-
*Development*: 0.11.1-SNAPSHOT
227+
*Development*: 0.12.0-SNAPSHOT
222228

223229
Logging
224230
-------
@@ -284,6 +290,11 @@ Technology
284290
Change log
285291
----------
286292

293+
#### Version 0.12.0 (7 Dec 2016)
294+
295+
* support for dynamic port allocation
296+
* node address is generated from bind address if not specified
297+
287298
#### Version 0.11.1 (30 Nov 2016)
288299

289300
* bug fix

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import sbtassembly.AssemblyKeys._
55
object BuildSettings {
66
val buildSettings = Defaults.coreDefaultSettings ++ Seq (
77
organization := "org.elasticmq",
8-
version := "0.11.1",
8+
version := "0.12.0",
99
scalaVersion := "2.11.8",
1010
crossScalaVersions := Seq(scalaVersion.value, "2.12.0"),
1111

rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/SQSRestServerBuilder.scala

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream
44
import java.nio.ByteBuffer
55
import java.security.MessageDigest
66
import java.util.concurrent.TimeUnit
7+
import java.util.concurrent.atomic.AtomicReference
78

89
import akka.actor.{ActorRef, ActorSystem, Props}
910
import akka.http.scaladsl.Http
@@ -22,6 +23,7 @@ import scala.collection.mutable.ArrayBuffer
2223
import scala.concurrent.duration._
2324
import scala.concurrent.{Await, Future}
2425
import scala.util.control.Exception._
26+
import scala.util.control.NonFatal
2527
import scala.xml.{EntityRef, _}
2628

2729
/**
@@ -32,13 +34,14 @@ import scala.xml.{EntityRef, _}
3234
* <ul>for `sqsLimits`: relaxed
3335
* </li>
3436
*/
35-
object SQSRestServerBuilder extends TheSQSRestServerBuilder(None, None, "", 9324, NodeAddress(), SQSLimits.Strict)
37+
object SQSRestServerBuilder extends TheSQSRestServerBuilder(None, None, "", 9324, NodeAddress(), true, SQSLimits.Strict)
3638

3739
case class TheSQSRestServerBuilder(providedActorSystem: Option[ActorSystem],
3840
providedQueueManagerActor: Option[ActorRef],
3941
interface: String,
4042
port: Int,
4143
serverAddress: NodeAddress,
44+
generateServerAddress: Boolean,
4245
sqsLimits: SQSLimits.Value) extends Logging {
4346

4447
/**
@@ -65,15 +68,15 @@ case class TheSQSRestServerBuilder(providedActorSystem: Option[ActorSystem],
6568
def withPort(_port: Int) = this.copy(port = _port)
6669

6770
/**
68-
* Will use port zero for automatic assignment.
71+
* Will assign port automatically (uses port 0). The port to which the socket binds will be logged on successful startup.
6972
*/
7073
def withDynamicPort() = withPort(0)
7174

7275
/**
7376
* @param _serverAddress Address which will be returned as the queue address. Requests to this address
7477
* should be routed to this server.
7578
*/
76-
def withServerAddress(_serverAddress: NodeAddress) = this.copy(serverAddress = _serverAddress)
79+
def withServerAddress(_serverAddress: NodeAddress) = this.copy(serverAddress = _serverAddress, generateServerAddress = false)
7780

7881
/**
7982
* @param _sqsLimits Should "real" SQS limits be used (strict), or should they be relaxed where possible (regarding
@@ -84,12 +87,14 @@ case class TheSQSRestServerBuilder(providedActorSystem: Option[ActorSystem],
8487
def start(): SQSRestServer = {
8588
val (theActorSystem, stopActorSystem) = getOrCreateActorSystem
8689
val theQueueManagerActor = getOrCreateQueueManagerActor(theActorSystem)
87-
val theServerAddress = serverAddress
90+
val theServerAddress = if (generateServerAddress) NodeAddress(host = if (interface.isEmpty) "localhost" else interface, port = port) else serverAddress
8891
val theLimits = sqsLimits
8992

9093
implicit val implicitActorSystem = theActorSystem
9194
implicit val implicitMaterializer = ActorMaterializer()
9295

96+
val currentServerAddress = new AtomicReference[NodeAddress](theServerAddress)
97+
9398
val env = new QueueManagerActorModule
9499
with QueueURLModule
95100
with SQSLimitsModule
@@ -110,7 +115,7 @@ case class TheSQSRestServerBuilder(providedActorSystem: Option[ActorSystem],
110115
with PurgeQueueDirectives
111116
with AttributesModule {
112117

113-
var serverAddress = theServerAddress
118+
def serverAddress = currentServerAddress.get()
114119
lazy val actorSystem = theActorSystem
115120
lazy val materializer = implicitMaterializer
116121
lazy val queueManagerActor = theQueueManagerActor
@@ -159,17 +164,19 @@ case class TheSQSRestServerBuilder(providedActorSystem: Option[ActorSystem],
159164

160165
appStartFuture.onSuccess {
161166
case sb: Http.ServerBinding =>
162-
env.serverAddress = NodeAddress(
163-
env.serverAddress.protocol,
164-
env.serverAddress.host,
165-
sb.localAddress.getPort,
166-
env.serverAddress.contextPath
167-
)
167+
if (generateServerAddress && port != sb.localAddress.getPort) {
168+
currentServerAddress.set(theServerAddress.copy(port = sb.localAddress.getPort))
169+
}
168170

169171
TheSQSRestServerBuilder.this.logger.info("Started SQS rest server, bind address %s:%d, visible server address %s"
170172
.format(interface, sb.localAddress.getPort, if (env.serverAddress.isWildcard) "* (depends on incoming request path) " else env.serverAddress.fullAddress))
171173
}
172174

175+
appStartFuture.onFailure {
176+
case NonFatal(e) =>
177+
TheSQSRestServerBuilder.this.logger.error("Cannot start SQS rest server, bind address %s:%d".format(interface, port), e)
178+
}
179+
173180
SQSRestServer(appStartFuture, () => {
174181
appStartFuture.flatMap { sb =>
175182
stopActorSystem()

server/src/main/resources/reference.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ rest-sqs {
2121
sqs-limits = strict
2222
}
2323

24+
// Should the node-address be generated from the bind port/hostname
25+
// Set this to true e.g. when assigning port automatically by using port 0.
26+
generate-node-address = false
27+
2428
queues {
2529
// queueName1 = {
2630
// // all optional

server/src/main/scala/org/elasticmq/server/ElasticMQServer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ class ElasticMQServer(config: ElasticMQServerConfig) extends Logging {
3030

3131
private def createBase(): ActorRef = {
3232
config.storage match {
33-
case config.InMemoryStorage => {
33+
case config.InMemoryStorage =>
3434
actorSystem.actorOf(Props(new QueueManagerActor(new NowProvider())))
35-
}
3635
}
3736
}
3837

@@ -44,6 +43,7 @@ class ElasticMQServer(config: ElasticMQServerConfig) extends Logging {
4443
config.restSqs.bindHostname,
4544
config.restSqs.bindPort,
4645
config.nodeAddress,
46+
config.generateNodeAddress,
4747
config.restSqs.sqsLimits).start()
4848

4949
server.waitUntilStarted()

server/src/main/scala/org/elasticmq/server/ElasticMQServerConfig.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class ElasticMQServerConfig(config: Config) {
3131
subConfig.getString("context-path"))
3232
}
3333

34+
val generateNodeAddress = config.getBoolean("generate-node-address")
35+
3436
// Optionally expose the REST SQS interface
3537

3638
class RestSqsConfiguration {

0 commit comments

Comments
 (0)