Cannot connect to compose.io hosted rethinkdb with clojure - clojure

I'm using the clojure rethinkdb library https://github.com/apa512/clj-rethinkdb - here's my connection snippet:
(ns rethink.core
(:require
[environ.core]
[cheshire.core :as json]
[org.httpkit.client :as http]
[rethinkdb.query :as r]))
(defn rethink-connect
[]
(r/connect :host (environ.core/env :rethinkdb-host)
:port (environ.core/env :rethinkdb-port)
:db (environ.core/env :rethinkdb-db)
:auth-key (environ.core/env :rethinkdb-auth)))
(defn record-event!
[event collection]
(let [r (with-open [conn (rethink-connect)]
(-> (r/table collection)
(r/insert [event])
(r/run conn)))]))
But I keep getting the error:
clojure.lang.ExceptionInfo: Error connecting to RethinkDB database
core.clj:4617 clojure.core/ex-info
core.clj:4617 clojure.core/ex-info
core.clj:88 rethinkdb.core/connect
core.clj:43 rethinkdb.core/connect
RestFn.java:619 clojure.lang.RestFn.invoke
core.clj:10 rethink.core/rethink-connect
core.clj:8 rethink.core/rethink-connect
core.clj:17 rethink.core/record-event!
core.clj:15 rethink.core/record-event!
core.clj:23 webhook.core/record-event!
core.clj:21 webhook.core/record-event!
handler.clj:11 webhook.handler/webhook-post
handler.clj:8 webhook.handler/webhook-post
handler.clj:9 app.handler/fn
handler.clj:9 app.handler/fn
core.clj:135 compojure.core/make-route[fn]
core.clj:122 compojure.core/wrap-route-middleware[fn]
core.clj:126 compojure.core/wrap-route-info[fn]
core.clj:45 compojure.core/if-route[fn]
core.clj:27 compojure.core/if-method[fn]
core.clj:151 compojure.core/routing[fn]
core.clj:2592 clojure.core/some
core.clj:2583 clojure.core/some
core.clj:151 compojure.core/routing
core.clj:148 compojure.core/routing
RestFn.java:139 clojure.lang.RestFn.applyTo
core.clj:648 clojure.core/apply
core.clj:641 clojure.core/apply
core.clj:156 compojure.core/routes[fn]
keyword_params.clj:35 ring.middleware.keyword-params/wrap-keyword-params[fn]
params.clj:64 ring.middleware.params/wrap-params[fn]
absolute_redirects.clj:38 ring.middleware.absolute-redirects/wrap-absolute-redirects[fn]
content_type.clj:30 ring.middleware.content-type/wrap-content-type[fn]
default_charset.clj:26 ring.middleware.default-charset/wrap-default-charset[fn]
not_modified.clj:52 ring.middleware.not-modified/wrap-not-modified[fn]
Var.java:379 clojure.lang.Var.invoke
reload.clj:22 ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:23 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:86 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:20 ring.adapter.jetty/proxy-handler[fn]
(Unknown Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:369 org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:486 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:944 org.eclipse.jetty.server.AbstractHttpConnection.content
AbstractHttpConnection.java:1005 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content
HttpParser.java:865 org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:240 org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:668 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52 org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:745 java.lang.Thread.run
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character
RT.java:1177 clojure.lang.RT.intCast
tcp.clj:156 aleph.tcp/client
tcp.clj:126 aleph.tcp/client
core.clj:61 rethinkdb.core/connect
I'm getting the host "aws-us-xxx-1-portal.xxx.xxxx.com", port "15731", db "dev" and auth-key from my compose.io rethinkdb instance. The auth-key is the admin password taken from authentication credential provided by compose.io interface. Not sure what's going on.

Actually, I needed to use a :ca-cert parameter as well, with the certificate being provided from the compose.io web interface.

Related

Clojure nested json response

I am new to clojure and I am trying to make a simple API with 3 endpoints.
I am trying to implement an endpoint which will take each row of a query and put it to a json.
So I have an SQLite database. These are my entries for example:
{:timestamp 2020-09-11 14:29:30, :lat 36.0, :long 36.0, :user michav}
{:timestamp 2020-09-11 14:31:47, :lat 36.0, :long 36.0, :user michav}
So I want a json response like the below:
{:get
:status 200
:body {:timestamp "2020-09-11 14:29:30"
:lat 36.0
:long 36.0
:user "michav"}
{:timestamp "2020-09-11 14:31:47"
:lat 36.0
:long 36.0
:user "michav"}
}
}
Here is my code that I am trying to fix it in order to get the above result.
(def db
{:classname "org.sqlite.JDBC"
:subprotocol "sqlite"
:subname "db/database.db"
})
(defn getparameter [req pname] (get (:params req) pname))
(defn output
"execute query and return lazy sequence"
[]
(query db ["select * from traffic_users"]))
(defn print-result-set
"prints the result set in tabular form"
[result-set]
(doseq [row result-set]
(println row)))
(defn request-example [req]
(response {:get {:status 200
:body (-> (doseq [row output]
{:timestamp (getparameter row :timestamp) :lat (getparameter row :lat) :long (getparameter row :long) :user (getparameter row :user)} ))
}}))
(defroutes my_routes
(GET "/request" [] request-example)
(route/resources "/"))
(def app (-> #'my_routes wrap-cookies wrap-keyword-params wrap-params wrap-json-response))
The error I encounter is the following :
java.lang.IllegalArgumentException: Don't know how to create ISeq from: mybank.core$output
RT.java:557 clojure.lang.RT.seqFrom
RT.java:537 clojure.lang.RT.seq
core.clj:137 clojure.core/seq
core.clj:137 clojure.core/seq
core.clj:65 mybank.core/request-example[fn]
core.clj:65 mybank.core/request-example
core.clj:63 mybank.core/request-example
response.clj:47 compojure.response/eval1399[fn]
response.clj:7 compojure.response/eval1321[fn]
core.clj:158 compojure.core/wrap-response[fn]
core.clj:128 compojure.core/wrap-route-middleware[fn]
core.clj:137 compojure.core/wrap-route-info[fn]
core.clj:146 compojure.core/wrap-route-matches[fn]
core.clj:185 compojure.core/routing[fn]
core.clj:2701 clojure.core/some
core.clj:2692 clojure.core/some
core.clj:185 compojure.core/routing
core.clj:182 compojure.core/routing
RestFn.java:139 clojure.lang.RestFn.applyTo
core.clj:667 clojure.core/apply
core.clj:660 clojure.core/apply
core.clj:192 compojure.core/routes[fn]
Var.java:384 clojure.lang.Var.invoke
cookies.clj:171 ring.middleware.cookies/wrap-cookies[fn]
keyword_params.clj:32 ring.middleware.keyword-params/wrap-keyword-params[fn]
params.clj:57 ring.middleware.params/wrap-params[fn]
json.clj:42 ring.middleware.json/wrap-json-response[fn]
Var.java:384 clojure.lang.Var.invoke
reload.clj:18 ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:27 ring.adapter.jetty/proxy-handler[fn]
(Unknown Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:127 org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:500 org.eclipse.jetty.server.Server.handle
HttpChannel.java:386 org.eclipse.jetty.server.HttpChannel.lambda$handle$1
HttpChannel.java:562 org.eclipse.jetty.server.HttpChannel.dispatch
HttpChannel.java:378 org.eclipse.jetty.server.HttpChannel.handle
HttpConnection.java:270 org.eclipse.jetty.server.HttpConnection.onFillable
AbstractConnection.java:311 org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded
FillInterest.java:103 org.eclipse.jetty.io.FillInterest.fillable
ChannelEndPoint.java:117 org.eclipse.jetty.io.ChannelEndPoint$2.run
EatWhatYouKill.java:336 org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask
EatWhatYouKill.java:313 org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce
EatWhatYouKill.java:171 org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce
EatWhatYouKill.java:135 org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce
QueuedThreadPool.java:806 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:938 org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run
(Unknown Source) java.lang.Thread.run
Your mistake is on this line:
(doseq [row output] ...
The error message
Don't know how to create ISeq from: mybank.core$output
gives the clue. The variable output is the function, not a sequence like doseq expects. You meant to call the output function, so you need to use parentheses to create a function call like:
(doseq [row (output)] ...
Update
You need to include an external library to convert between EDN data and a JSON string. My favorite way is my own library Tupelo Clojure. Use it like this:
(ns tst.demo.core
(:use tupelo.core tupelo.test))
(let [data [{:timestamp "2020-09-11 14:29:30", :lat 36.0, :long 36.0, :user "michav"}
{:timestamp "2020-09-11 14:31:47", :lat 36.0, :long 36.0, :user "michav"}]]
(println (edn->json data)))
with result:
[{"timestamp":"2020-09-11 14:29:30","lat":36.0,"long":36.0,"user":"michav"},
{"timestamp":"2020-09-11 14:31:47","lat":36.0,"long":36.0,"user":"michav"}]
You will need a line like this in your project.clj:
[tupelo "20.08.27"]
Please also see this template project for an easy way to get started. Enjoy!

Clojure file upload with hiccup, ring, compojure

I am trying to create file upload system. However, i stuck and can't resolve the problem.
My core.cjl
(ns hiccup-templating.core
(:require [compojure.core :refer [defroutes GET ANY POST]]
[compojure.route :as route]
[compojure.handler :as handler]
[ring.adapter.jetty :as jetty]
[hiccup-templating.views.layout :as layout]
[hiccup-templating.views.contents :as contents]
(ring.middleware [multipart-params :as mp])
(clojure.contrib [duck-streams :as ds])))
(defn upload-file
[file]
(ds/copy (file :tempfile) (ds/file-str (str (rand-int 30) ".jpg")))
(layout/application "Home" (contents/succes)))
(defroutes public-routes
(GET "/" [] (layout/application "Home" (contents/index)))
(mp/wrap-multipart-params
(POST "/file" {params :params} (upload-file (get params "file")))))
(def application (handler/site public-routes))
(defn -main []
(let [port (Integer/parseInt (or (System/getenv "PORT") "8080"))]
(jetty/run-jetty application {:port port :join? false})))
So i have such an error.
2017-04-25 17:00:57.934:WARN:oejs.AbstractHttpConnection:/file
java.lang.NullPointerException
at hiccup_templating.core$upload_file.invoke(core.clj:14)
at hiccup_templating.core$fn__3152.invoke(core.clj:20)
at compojure.core$make_route$fn__489.invoke(core.clj:94)
at compojure.core$if_route$fn__473.invoke(core.clj:40)
at compojure.core$if_method$fn__466.invoke(core.clj:25)
at ring.middleware.multipart_params$wrap_multipart_params$fn__947.invoke(multipart_params.clj:107)
at compojure.core$routing$fn__495.invoke(core.clj:107)
at clojure.core$some.invoke(core.clj:2443)
at compojure.core$routing.doInvoke(core.clj:107)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:619)
at compojure.core$routes$fn__499.invoke(core.clj:112)
at ring.middleware.keyword_params$wrap_keyword_params$fn__854.invoke(keyword_params.clj:32)
at ring.middleware.nested_params$wrap_nested_params$fn__903.invoke(nested_params.clj:70)
at ring.middleware.params$wrap_params$fn__820.invoke(params.clj:58)
at ring.middleware.multipart_params$wrap_multipart_params$fn__947.invoke(multipart_params.clj:107)
at ring.middleware.flash$wrap_flash$fn__2119.invoke(flash.clj:31)
at ring.middleware.session$wrap_session$fn__2099.invoke(session.clj:85)
at ring.adapter.jetty$proxy_handler$fn__2209.invoke(jetty.clj:18)
at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$0.handle(Unknown Source)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:363)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
I will be glad if somebody give me the way how to understand the problem i have.
I also had this problem
Cannot find the path you want to copy the file to.
Make sure you follow the path.
I am using Linux operating system and I gave this address and the problem was solved.
(copy actual-file (File. (format "/home/naser/Desktop/%s" file-name)))

java.lang.IllegalArgumentException: No implementation of method: :route-matches of protocol: #'clout.core/Route

I have two files of interest:
build.boot
(set-env!
:source-paths #{"src/clj" "src/cljs" "test/clj"}
:resource-paths #{"html" "target/main.js"}
:dependencies '[[adzerk/boot-cljs "0.0-3308-0"]
[adzerk/boot-cljs-repl "0.1.10-SNAPSHOT"]
[adzerk/boot-reload "0.3.1"]
[adzerk/boot-test "1.0.4"]
[cljsjs/hammer "2.0.4-4"]
[compojure "1.3.1"]
[com.datomic/datomic-pro "0.9.5186"]
[hiccup "1.0.5"]
[org.clojure/clojure "1.7.0-RC1"]
[org.clojure/clojurescript "0.0-3308"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[org.clojure/test.check "0.7.0"]
[org.omcljs/om "0.8.8"]
[pandeiro/boot-http "0.6.3-SNAPSHOT"]
[ring/ring-devel "1.4.0-RC1"]
[http-kit "2.1.18"]])
(require
'[adzerk.boot-cljs :refer [cljs]]
'[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
'[adzerk.boot-reload :refer [reload]]
'[adzerk.boot-test :refer [test]]
'[pandeiro.boot-http :refer [serve]])
(task-options!
cljs {:source-map true
:optimizations :none
:pretty-print true})
(deftask build
"Build an uberjar of this project that can be run with java -jar"
[]
(comp
(cljs)
(aot :namespace '#{vidiot.server})
(pom :project 'vidiot
:version "0.1.0")
(uber)
(jar :main 'vidiot.server)))
and src/clj/vidiot/server.clj
(ns vidiot.server
(:gen-class)
(:require
[compojure.core :refer :all]
[compojure.route :as route]
[hiccup.core :refer :all]
[org.httpkit.server :refer :all]
[ring.middleware.reload :as reload]
[ring.util.response :as response]))
(defonce server (atom nil))
(defroutes all-routes
(GET "/" [] (response/redirect "index.html"))
(GET "/ws" [request]
(with-channel request channel
(on-close
channel
(fn [status]
(println "channel closed: " status)))
(on-receive
channel
(fn [data] ;; echo it back
(send! channel data)))))
(route/files "/" {:root "target"})
(route/not-found (response/response (html [:div#erro "Page Not Found"]))))
(defn -main [& args]
(run-server all-routes {:port 8080}))
Then I,
> boot build
> java -jar target/vidiot-0.1.0.jar
Followed by going to localhost:9090 in my browser, the terminal prints.
java.lang.IllegalArgumentException: No implementation of method: :route-matches of protocol: #'clout.core/Route found for class: clout.core.CompiledRoute
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:554)
at clout.core$eval5590$fn__5591$G__5581__5598.invoke(core.clj:39)
at compojure.core$if_route$fn__5887.invoke(core.clj:40)
at compojure.core$if_method$fn__5879.invoke(core.clj:27)
at compojure.core$routing$fn__5918.invoke(core.clj:127)
at clojure.core$some.invoke(core.clj:2568)
at compojure.core$routing.doInvoke(core.clj:127)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:630)
at compojure.core$routes$fn__5922.invoke(core.clj:132)
at org.httpkit.server.HttpHandler.run(RingHandler.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I can fix this issue by downgrading :dependencies in build.boot to [compojure "1.1.6"].
So, my question is, why can't I use [compojure "1.3.4"] (the most recent version at this writing) when building my uberjar?
Placing aot task after uber fixes the issue.
(task-options! pom {:project 'my-project
:version "0.1.0"}
jar {:main 'my-project.core}
aot {:namespace '#{my-project.core}})
(deftask build []
(comp (pom)
(uber)
(aot)
(jar)))
I was able to fix this by adding an exclude for the clout folder. It looks like uberjar is unpacking some compiled clout files on top of those compiled from project source. Example from my project:
(comp (cljs :compiler-options {:output-to "js/main.js"})
(aot :namespace '#{zoondka-maps.server zoondka-maps.handler})
(pom :project (symbol (:name project))
:version (:version project))
(uber :exclude (conj pod/standard-jar-exclusions #".*\.html" #"clout/.*"))
(jar :file (str (:name project) ".jar")
:main 'zoondka-maps.server)))

how to connect to remote rabbitmq using clojure

I am using langohr to connect rabbitmq, if I don't specify any connection string, it works well and it connects to local server, but I want to connect to remote server. So I have the following code. I am using connection string of amqp://bigdata:bigdata#s1:5672, s2 is the hostname of the remote server.
let [ a (println rabbitmq-url)
rmq-conn (rmq/connect {:uri rabbitmq-url})
a (println rabbitmq-url)]
But it throws the error of the following
$ lein run
amqp://bigdata:bigdata#s1:5672
Exception in thread "main" java.io.IOException, compiling:(/tmp/form-init589039011205967992.clj:1:71)
at clojure.lang.Compiler.load(Compiler.java:7142)
at clojure.lang.Compiler.loadFile(Compiler.java:7086)
at clojure.main$load_script.invoke(main.clj:274)
at clojure.main$init_opt.invoke(main.clj:279)
at clojure.main$initialize.invoke(main.clj:307)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:420)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:376)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:36)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:83)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:609)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:651)
at com.novemberain.langohr.Connection.init(Connection.java:92)
at langohr.core$connect.invoke(core.clj:93)
at clojurewerkz.testcom.core$create_message_from_database.invoke(core.clj:33)
at clojurewerkz.testcom.core$create_message_from_database_loop.invoke(core.clj:53)
at clojurewerkz.testcom.core$_main.doInvoke(core.clj:60)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.Var.invoke(Var.java:375)
at user$eval5.invoke(form-init589039011205967992.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6703)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.load(Compiler.java:7130)
... 11 more
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
... 27 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534)
at java.lang.Thread.run(Thread.java:745)
First, make sure that RabbitMQ is running on the remote server. Second, check if the user that is connecting to that instance has the permission to do so.
The same issue as below: my account doesn't have access to virtual hosts.
RabbitMQ new connection refused due to SocketException
try this code.
First, put these libs into your project.clj
;;rabbitmq client
[com.novemberain/langohr "2.11.0"]
;;logging
[org.clojure/tools.logging "0.2.4"]
Then, make necessary imports in your clj file:
(:require
;logging
[clojure.tools.logging :as log]
;;rabbitmq
[langohr.core :as rmq]
[langohr.channel :as lch]
[langohr.queue :as lq]
[langohr.exchange :as le]
[langohr.basic :as lb] ))
And here is connect function:
(defn get-mq-connect
"This function connects to RabbitMQ.
params example: {:host \"localhost\" :port 5672 :username \"guest\" :password \"guest\" :vhost \"/\"}
Returns: connect object - connection successful, nil - error occured."
[params]
(try
(log/trace params)
(rmq/connect params)
(catch Exception e
(log/error (.getMessage e))
(println "MQ connection error:" (.getMessage e)))))
You can call this function that way:
(let [ params {:host "myhost.com" :port 5672 :username "admin" :password "StrongPassw098" :vhost "/"}
conn (get-mq-connect mq-params)]
(when-not (nil? conn)
(let [ch (lch/open conn)]
(while (not #stop-flag?)
(do
;;put here your code
))
(rmq/close ch)
(rmq/close conn)))))

Getting started with liberator

I am new to clojure and liberator.
I am trying to get started with liberator but I am stuck on the following error.
Here is my code that starts the webserver and defines the routes:
(ns game-of-life.core
(:require
[ring.util.response :as resp]
[compojure.route :as route]
[ring.adapter.jetty :as jetty])
(:use
[ring.middleware.multipart-params :only [wrap-multipart-params]]
[ring.util.response :only [header]]
[compojure.core :only [context ANY routes defroutes]]
[compojure.handler :only [api]]))
(defn assemble-routes []
(->
(routes
(ANY "/" [] (resp/redirect "/index.html"))
(route/resources "/"))))
(def handler
(-> (assemble-routes))
(defn start [options]
(jetty/run-jetty #'handler (assoc options :join? false)))
(defn -main
([port]
(start {:port (Integer/parseInt port)}))
([]
(-main "3000")))
When I run lein ring server, I get a java.lang.NullPointerException with the following stacktrace:
reload.clj:18 ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:18 ring.adapter.jetty/proxy-handler[fn] (Unknown
Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$0.handle
HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:363 org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:483 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:920 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:982 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:635 org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235 org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:628 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52 org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:744 java.lang.Thread.run
I think it will work better if your handler function get the request argument.
Can you try changing the dependencies like this? These versions and the following config totally works for me: (including reloading)
(defproject ..........
:dependencies [[org.clojure/clojure "1.5.1"]
[liberator "0.11.0"]
[ring/ring-core "1.1.8"]
[ring/ring-jetty-adapter "1.1.8"]
[compojure "1.1.3"]]
:main game-of-life.core
:min-lein-version "2.0.0"
:plugins [[lein-ring "0.8.10"]]
:ring {:handler game-of-life.core/handler})
Plus the handler should be
(def handler
(-> (assemble-routes)))