Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change start of ElasticMq from rest only to server+rest for backwards compatibility (i.e: python boto) #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(def project-version "1.0.0-SNAPSHOT")
(def project-version "1.0.1-SNAPSHOT")
(def build-meta (str "YOPA " project-version " - built on: " (java.util.Date.)))
(def ring-version "1.3.2")
(def aws-sdk-version "1.10.5.1")
Expand Down Expand Up @@ -37,7 +37,8 @@
[circleci/clj-yaml "0.5.3"]
[de.ubercode.clostache/clostache "1.4.0"]

[org.elasticmq/elasticmq-rest-sqs_2.11 "0.8.8" :exclusions [joda-time]]
[org.elasticmq/elasticmq-server_2.11 "0.8.12" :exclusions [joda-time]]
[org.elasticmq/elasticmq-rest-sqs_2.11 "0.8.12" :exclusions [joda-time]]
[amazonica "0.3.29" :exclusions [com.amazonaws/aws-java-sdk]]
[com.amazonaws/aws-java-sdk-sqs ~aws-sdk-version :exclusions [joda-time]]
[com.amazonaws/aws-java-sdk-sns ~aws-sdk-version :exclusions [joda-time]]
Expand All @@ -53,9 +54,7 @@
[ring/ring-core ~ring-version]
[ring/ring-jetty-adapter ~ring-version]

[org.jruby/jruby "9.0.0.0" :exclusions [com.github.jnr/jffi
com.github.jnr/jnr-x86asm
joda-time]]
[org.jruby/jruby "9.0.0.0" :exclusions [joda-time]]
]

:repositories
Expand Down
52 changes: 40 additions & 12 deletions src/com/unbounce/yopa/sqs_server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,53 @@
(:require [amazonica.core :as aws]
[amazonica.aws.sqs :as sqs]
[clojure.tools.logging :as log])
(:import org.elasticmq.rest.sqs.SQSRestServerBuilder
org.elasticmq.NodeAddress))
(:import org.elasticmq.server.ElasticMQServer
org.elasticmq.server.ElasticMQServerConfig
com.typesafe.config.ConfigFactory
com.typesafe.config.Config))

(def config-string "{
\"akka.http.server.parsing.illegal-header-warnings\": \"off\",
\"akka\": {
\"loggers\": [\"akka.event.slf4j.Slf4jLogger\"],
\"loglevel\": \"DEBUG\",
\"logging-filter\": \"akka.event.slf4j.Slf4jLoggingFilter\",
\"log-dead-letters-during-shutdown\": false
},
\"akka.http.server.request-timeout\": \"21 s\",
\"akka.http.server.parsing.max-uri-length\": \"256k\",
\"storage\": {
\"type\": \"in-memory\"
},
\"node-address\": {
\"protocol\": \"http\",
\"host\": \"%s\",
\"port\": \"%d\",
\"context-path\": \"\"
},
\"rest-sqs\": {
\"enabled\": true,
\"bind-hostname\": \"%s\",
\"bind-port\": \"%d\",
\"sqs-limits\": \"relaxed\"
},
\"queues\": {}
}")

(def ^:private ^:dynamic server (atom nil))

(defn- make-server [host bind-address port]
(let [address (NodeAddress. "http", host, port, "")]
(-> (SQSRestServerBuilder/withPort port)
(.withInterface bind-address)
(.withPort port)
(.withServerAddress address)
(.start))))
(defn- make-main-server [host bind-address port]
(let [formatted-config (format config-string host port bind-address port)]
(log/info formatted-config)
(let [typesafe-config (ConfigFactory/parseString formatted-config)]
(let [config (ElasticMQServerConfig. typesafe-config)]
(-> (ElasticMQServer. config)
(.start))))))

(defn start [host bind-address port]
(reset! server (make-server host bind-address port))
(.waitUntilStarted @server)
(reset! server (make-main-server host bind-address port))
(log/info (format "Active SQS endpoint: http://%s:%d" bind-address port)))

(defn stop []
(when @server
(.stopAndWait @server)
(reset! server nil)))