Commits

Alvaro Videla committed 2b4de04

handles connections to cloudfoundry

  • Participants
  • Parent commits 4ecb129

Comments (0)

Files changed (2)

src/resizer/consumer.clj

         [langohr.consumers :as lhcons]
         [langohr.queue :as lhq]
         [langohr.basic :as lhb]
+        [resizer.cfenv :as cf]
         [resizer.resizer :as rz]))
 
-(defonce ^Connection conn (lhc/connect)) ;; TODO find the right parameters from the java utils cf lib
+(defn rabbitmq-connect []
+  (if (cf/cloudfoundry?)
+    (lhc/connect (lhc/settings-from (cf/rabbit-url)))
+    (lhc/connect)))
+
+(defonce ^Connection conn (rabbitmq-connect))
 
 ;; TODO if resize fails publish a message or log that it failed to process the image.
 (defn process-message [ch metadata payload]

src/resizer/resizer.clj

   (:require [clojure.string :as cs]
             [monger.core :as mg]
             [monger.gridfs :as gfs])
-  (:use [monger.gridfs :only [store-file make-input-file filename content-type metadata]])
+  (:use [monger.gridfs :only [store-file make-input-file filename content-type metadata]]
+        [resizer.cfenv :as cf])
   (:import [java.awt.image BufferedImage]
            [java.io ByteArrayOutputStream]
            [javax.imageio ImageIO]))
 
 (defonce height 225)
 (defonce width 225)
-(defonce db "cloudstagram")
+(defonce default-url "mongodb://127.0.0.1/cloudstagram")
 
-(mg/connect!) ;; TODO find the right parameters from the java utils cf lib
-(mg/set-db! (mg/get-db db))
+(defn mongo-connect []
+  (if (cf/cloudfoundry?)
+    (mg/connect-via-uri! (cf/mongo-url))
+    (mg/connect-via-uri! default-url)))
 
 (defn get-type [img]
   (if (= (.getType img) 0)