connect with jmx secured by username/password - clojure

Using clojure.java.jmx I'm trying to connect with JMX server protected with username/password:
(jmx/with-connection {:host "my.server", :port 50001 :environment {"jmx.remote.credentials" ["username" "password"]}} (jmx/mbean "java.lang:type=OperatingSystem"))
But what I get is:
ClassNotFoundException clojure.lang.PersistentVector (no security manager: RMI class loader disabled) sun.rmi.server.LoaderHandler.loadClass (LoaderHandler.java:396)
Aby thoughts what's happened here?

aghh... sorry guys. I just found a reason. as a clojure newbe I tried to send environment parameters as clojure Vector instead of java array of Strings. Following is the snippet which solves my problem:
(jmx/with-connection {:host "my.server", :port 50001 :environment {"jmx.remote.credentials" (into-array String ["username" "password"])}} (jmx/mbean "java.lang:type=OperatingSystem"))

Related

How to listen to slack messages using clojure?

I am using clj-slack start method for getting the web-socket url and then passing it to the connect method of gniazdo for listening to the web-socket.
(require '[clj-slack.rtm :as slack])
(require '[gniazdo.core :as ws])
(def connection {:api-url "https://slack.com/api" :token "your token"})
(defn reset-conn [options]
(def socket
(ws/connect
(:url (slack/start options))
:on-receive #(prn 'received %))))
(reset-conn connection)
This code is working fine but it only provides information about who is active or away for slack:
received"{\"type\":\"presence_change\",\"presence\":\"active\",\"user\":\"U7BCQHWHY\"}"
But I also want to listen to the messages.
I don't know why messages are not printed though it was stated in slack-api documentation that rtm(real time messaging) is for messaging session.

Datomic: java.lang.NoClassDefFoundError when trying to connect to an ddb transactor deployed to aws

I have deployed a datomic transactor to an AWS cloud formation, connected to a DyanmoDB as storage. I'm able to connect to the transactor if I go to my local datomic directory (version 0.9.5.44) and use the repl:
=> (def uri "datomic:ddb://us-east-1/datemo/test-db?aws_access_key_id={xxx}&aws_secret_key={yyy}")
=> (def conn (d/connect uri))
#object[datomic.peer.Connection 0x5e5ddfbc "{:unsent-updates-queue 0, :pending-txes 0,:next-t 1000, :basis-t 63, :index-rev 0, :db-id \"test-db-ab4b8028-e25b-4431-b2a2-c7173b4c9918\"}"]
If, however, I do the same in my project's repl, it does not work, and instead I get the following error:
CompilerException java.lang.NoClassDefFoundError: Could not initialize
class datomic.ddb_cluster__init,
compiling:(form-init1336530578825920965.clj:1:11)
Incidentally, if I try to connect to my usual datomic dev transactor it works just fine. Does anyone know what I might be doing wrong here? The error seems to suggest that the class is not even present...
You need to include both the Datomic Peer library and the AWS SDK as dependencies in your project to connect to a DDB-backed instance.
This section of the documentation: http://docs.datomic.com/storage.html#sec-6-1 contains details of including the AWS SDK.
-Marshall

How to test http requests with cljs-http using lein doo phantom

While running my tests with lein doo phantom, I receive a -1 status response and an empty string as the body. However, when I run the test in the repl, I am able to retrieve the request data with a 200 status response and the appropriate data in the body. Is this because a manytomany channel is being returned first as mentioned below, thus giving me the inappropriate response? If so, how could I account for this?
https://github.com/r0man/cljs-http#async-response-handling
I also thought maybe I need to use a timeout to wait for the request to complete. If so, how would I apply that appropriately with my existing code? It looks like cljs-http has :timeout as a parameter but I haven't been ably to get it to work appropriately (assuming this is the cause of the issue).
(deftest test-async
(async done
(go (let [response (<! (http/get "http://localhost:3000/api/user/1"
{:with-credentials? false
:query-params {"id" 1}}))]
(is (= {:status 200}
(select-keys response [:status]))))
(done))))
Since you are running your test under phantomjs. Phantomjs default disable cross domain XHR access and your tests js are running on localhost,all external ajax calls are denied.
you can set the --web-security=false to allow your test to do cross domain ajax.
In your project.clj add this
:doo {:paths {:phantom "phantomjs --web-security=false"}}
more info about phantomjs
http://phantomjs.org/api/command-line.html

Fail to connect to queue with Immutant messaging

Currently I have an instance of ActiveMQ running, that I am attempting to connect to using immutant. Currently the code for this connection looks like so;
(defn make-ctx
[]
(log/debug "making context")
(let [ctx (m/context :host (:host immutant-host) :port (:port immutant-host))]
(log/debug "context created")
ctx))
(defn make-listener
[ctx]
(let [listener (m/listen topic #(log/debug %) :context ctx)]
(log/debug "listener created")
listener))
(defn immutant-test
[]
(log/debug "testing immutant messaging with ActiveMQ")
(let [ctx (make-ctx)
listener (make-listener ctx)]
(Thread/sleep 15000)
(.close listener)))
Though my code does not make it passed the make-ctx function. When it attempts to create the context I get the error
Exception in thread "main" java.lang.RuntimeException: javax.jms.JMSException: Failed to create session factory
at org.projectodd.wunderboss.messaging.jms.DestinationUtil.mightThrow(DestinationUtil.java:47)
at org.projectodd.wunderboss.messaging.jms.JMSMessagingSkeleton.createContext(JMSMessagingSkeleton.java:64)
at org.projectodd.wunderboss.messaging.jms.JMSMessagingSkeleton.createContext(JMSMessagingSkeleton.java:181)
at immutant.messaging$context.doInvoke(messaging.clj:84)
at clojure.lang.RestFn.invoke(RestFn.java:457)
at jms_test.core$make_ctx.invoke(core.clj:24)
at jms_test.core$immutant_test.invoke(core.clj:37)
at jms_test.core$_main.invoke(core.clj:158)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at jms_test.core.main(Unknown Source)
Caused by: javax.jms.JMSException: Failed to create session factory
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:107)
at org.projectodd.wunderboss.messaging.jms.JMSMessagingSkeleton$1.call(JMSMessagingSkeleton.java:73)
at org.projectodd.wunderboss.messaging.jms.DestinationUtil.mightThrow(DestinationUtil.java:45)
... 10 more
Caused by: HornetQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=HQ119013: Timed out waiting to receive cluster topology. Group:null]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:946)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669)
... 14 more
The immutant-host is defined as
(def immutant-host {:host "127.0.0.1" :port 61616})
I've been able to connect to my broker with the clamq libray ,and am able to send and receive messages with that. Though because the rest of the application is built with immutant messaging I'd like to stick with that library if possible to keep from having to support several messaging libraries.
Immutant is built on top of HornetQ, so can only connect to HornetQ servers by default. This is because the JMS spec doesn't provide a wire protocol, so each implementation has its own. However, if the remote ActiveMQ is actually Artemis, you can use wunderboss-artemis to enable using it from Immutant (note that the article states you have to use an incremental build of Immutant - that is no longer true, you can use Immutant 2.1.0).
If it's not Artemis, it wouldn't be too difficult to implement a wunderboss-activemq adapter using the artemis version as a guide.

Connecting to a datomic-free instance hosted on EC2 from outside AWS?

I've installed and run cldwalker's datomic-free receipe https://github.com/cldwalker/datomic-free on an EC2 instance.
;=> System started datomic:free://{EC2 private IP address}:4334/<DB-NAME>,
; storing data in: data
My free-transactor.properties file looks like this:
protocol=free
host={EC2 private IP address}
port=4334
h2-port=4335
h2-web-port=4336
I want to connect the database from outside EC2:
(require '[datomic.api :as d])
(def uri "datomic:free://{EC2 public IP address}:4334/om_async?h2-
port=4335&h2-web-port=4336&aws_secret_key={xxx}&aws_access_key_id={yyy}")
(d/create-database uri)
But I get:
clojure.lang.ExceptionInfo: Error communicating with HOST
{EC2 private IP address} on PORT 4334 :: {:timestamp 1418304487036,
:host "{EC2 private IP address}", :version "0.9.5078", :port 4334,
:username "{XXX}", :peer-version 2, :alt-host nil, :password "{YYY}",
:encrypt-channel true}
What should I do to make this work?
UPDATE:
I have found the "Free Transactor on EC2" thread in the Datomic Google Group: https://groups.google.com/d/msg/datomic/wBRZNyHm03o/0SdNhqjF27wJ
Does this means I can only connect to Datomic-free if my app run on the same server?
Would I have the same problem (not being able to access db from outside server) if I get Datomic-free hosted on linode or digitalocean?
Thanks in advance for your help!
I had a very similar problem ("Error communicating with HOST
on PORT 4334") and all I had to do was restart my computer, strangely enough. Something with the ports being tied up after having launched a local transactor, I think. Then again, you probably already tried that.
To allow remote peers access to embedded storage you must do three things:
choose two passwords for the embedded storage
set the storage-access property
add a password to the connection URI used by peers
Take a look at this link