Repository: softwaremill/elasticmq (scala)

Issue:
1.3.0 docker image breaks custom elasticmq.conf
Following the readme, we essentially start a container with the following command:

```
docker run --rm -v `pwd`/elasticmq.conf:/opt/elasticmq.conf softwaremill/elasticmq
```

the elasticmq.conf file we pass in is:

```
include classpath("application.conf")

queues {
    void { }
}
```

In 1.3.0, this is the output (note the lack of acknowledgement of the queue being created)

```
16:42:14.157 [main] INFO  org.elasticmq.server.Main$ - Starting ElasticMQ server (1.3.0) ...
16:42:14.746 [elasticmq-akka.actor.default-dispatcher-4] INFO  akka.event.slf4j.Slf4jLogger - Slf4jLogger started
16:42:15.874 [elasticmq-akka.actor.default-dispatcher-4] INFO  o.e.rest.sqs.TheSQSRestServerBuilder - Started SQS rest server, bind address 0.0.0.0:9324, visible server address http://localhost:9324
16:42:16.028 [elasticmq-akka.actor.default-dispatcher-4] INFO  o.e.r.s.TheStatisticsRestServerBuilder - Started statistics rest server, bind address 0.0.0.0:9325
16:42:16.029 [main] INFO  org.elasticmq.server.Main$ - === ElasticMQ server (1.3.0) started in 2397 ms ===
```

If i run the following command to use 1.2.3 instead:

```
docker run --rm -v `pwd`/elasticmq.conf:/opt/elasticmq.conf softwaremill/elasticmq:1.2.3
```

The queue is made correctly:

```
16:42:39.347 [main] INFO  org.elasticmq.server.Main$ - Starting ElasticMQ server (1.2.3) ...
16:42:39.960 [elasticmq-akka.actor.default-dispatcher-5] INFO  akka.event.slf4j.Slf4jLogger - Slf4jLogger started
16:42:41.086 [elasticmq-akka.actor.default-dispatcher-7] INFO  o.e.rest.sqs.TheSQSRestServerBuilder - Started SQS rest server, bind address 0.0.0.0:9324, visible server address http://localhost:9324
16:42:41.218 [elasticmq-akka.actor.default-dispatcher-7] INFO  o.e.r.s.TheStatisticsRestServerBuilder - Started statistics rest server, bind address 0.0.0.0:9325
16:42:41.291 [elasticmq-akka.actor.default-dispatcher-7] INFO  o.elasticmq.actor.QueueManagerActor - Creating queue QueueData(void,MillisVisibilityTimeout(30000),PT0S,PT0S,2021-10-19T16:42:41.244Z,2021-10-19T16:42:41.244Z,None,false,false,None,None,Map())
16:42:41.328 [main] INFO  org.elasticmq.server.Main$ - === ElasticMQ server (1.2.3) started in 2499 ms ===
```

Looks like there's something in 1.3.0 that breaks this, and the Readme has not been updated on how to insert custom conf files (or this break was not intended?)

Pull request description:
fixes #553

Patch:
diff --git a/server/src/main/scala/org/elasticmq/server/ElasticMQServer.scala b/server/src/main/scala/org/elasticmq/server/ElasticMQServer.scala
index cc1a549e4..75c69ec57 100644
--- a/server/src/main/scala/org/elasticmq/server/ElasticMQServer.scala
+++ b/server/src/main/scala/org/elasticmq/server/ElasticMQServer.scala
@@ -12,6 +12,7 @@ import org.elasticmq.rest.sqs.{SQSRestServer, TheSQSRestServerBuilder}
 import org.elasticmq.rest.stats.{StatisticsRestServer, TheStatisticsRestServerBuilder}
 import org.elasticmq.server.config.ElasticMQServerConfig
 import org.elasticmq.util.{Logging, NowProvider}
+import scala.concurrent.duration._
 
 import scala.concurrent.duration.Duration.Inf
 import scala.concurrent.{Await, ExecutionContextExecutor, Future}
@@ -19,6 +20,8 @@ import scala.concurrent.{Await, ExecutionContextExecutor, Future}
 class ElasticMQServer(config: ElasticMQServerConfig) extends Logging {
   val actorSystem = ActorSystem("elasticmq")
 
+  implicit val timeout: Timeout = Timeout(5.seconds)
+
   def start() = {
     val queueConfigStore: Option[ActorRef] = createQueueEventListener
     val queueManagerActor = createBase(queueConfigStore)
@@ -39,15 +42,22 @@ class ElasticMQServer(config: ElasticMQServerConfig) extends Logging {
 
     }
 
+    val logErrorsAndShutdown = { errors: List[ElasticMQError] =>
+      errors.foreach(error => logger.error(s"Could not start server because $error"))
+      shutdown()
+    }
+
     queueConfigStore match {
       case Some(queueConfigStoreActor) =>
-        createQueues(queueConfigStoreActor, queueManagerActor) match {
-          case Some(errors) =>
-            errors.foreach(error => logger.error(s"Could not start server because $error"))
-            shutdown()
+        restoreQueuesViaQueueEventListener(queueConfigStoreActor, queueManagerActor) match {
+          case Some(errors) => logErrorsAndShutdown(errors)
           case None =>
         }
       case None =>
+        createQueuesFromConfig(queueManagerActor) match {
+          case Some(errors) => logErrorsAndShutdown(errors)
+          case None =>
+        }
     }
 
     shutdown
@@ -111,12 +121,19 @@ class ElasticMQServer(config: ElasticMQServerConfig) extends Logging {
     }
   }
 
-  private def createQueues(queueConfigStore: ActorRef, queueManagerActor: ActorRef): Option[List[ElasticMQError]] = {
-    implicit val timeout: Timeout = {
-      import scala.concurrent.duration._
-      Timeout(5.seconds)
-    }
+  private def restoreQueuesViaQueueEventListener(queueEventListenerActor: ActorRef, queueManagerActor: ActorRef): Option[List[ElasticMQError]] =
+    Await.result(queueEventListenerActor ? QueueEvent.Restore(queueManagerActor), timeout.duration).swap.toOption
+
+  private def createQueuesFromConfig(queueManagerActor: ActorRef): Option[List[ElasticMQError]] = {
+    val errors = config
+      .baseQueues
+      .flatMap(createQueue =>
+        Await
+          .result(queueManagerActor ? org.elasticmq.msg.CreateQueue(createQueue.toQueueData), timeout.duration)
+          .swap
+          .toOption
+      )
 
-    Await.result(queueConfigStore ? QueueEvent.Restore(queueManagerActor), timeout.duration).swap.toOption
+    if (errors.nonEmpty) Some(errors) else None
   }
 }
diff --git a/server/src/main/scala/org/elasticmq/server/config/ElasticMQServerConfig.scala b/server/src/main/scala/org/elasticmq/server/config/ElasticMQServerConfig.scala
index 83467c79e..7b2a52177 100644
--- a/server/src/main/scala/org/elasticmq/server/config/ElasticMQServerConfig.scala
+++ b/server/src/main/scala/org/elasticmq/server/config/ElasticMQServerConfig.scala
@@ -74,10 +74,5 @@ class ElasticMQServerConfig(config: Config) extends Logging {
 
   val sqlQueuePersistenceConfig: SqlQueuePersistenceConfig = getSqlQueuePersistenceConfig
 
-  val baseQueues: List[CreateQueueMetadata] = {
-    if (queuesStorageEnabled || sqlQueuePersistenceConfig.enabled)
-      QueueConfigUtil.readPersistedQueuesFromConfig(config)
-    else
-      Nil
-  }
+  val baseQueues: List[CreateQueueMetadata] = QueueConfigUtil.readPersistedQueuesFromConfig(config)
 }


Test patch:
diff --git a/server/src/test/scala/org/elasticmq/server/config/ElasticMQServerConfigTest.scala b/server/src/test/scala/org/elasticmq/server/config/ElasticMQServerConfigTest.scala
index 5dd20e139..358f47912 100644
--- a/server/src/test/scala/org/elasticmq/server/config/ElasticMQServerConfigTest.scala
+++ b/server/src/test/scala/org/elasticmq/server/config/ElasticMQServerConfigTest.scala
@@ -11,8 +11,8 @@ class ElasticMQServerConfigTest extends AnyFunSuite with Matchers with OptionVal
     new ElasticMQServerConfig(ConfigFactory.load("conf/elasticmq"))
   }
 
-  test("Should not parse persisted queues when disabled") {
+  test("Should parse base queues") {
     val conf = new ElasticMQServerConfig(ConfigFactory.load("test"))
-    conf.baseQueues shouldBe Nil
+    conf.baseQueues.size shouldBe 8
   }
 }