 ;; TODO: tracking needs to be reviewed
 ;; TODO: display of events
 ;; TODO: per message vs per batch error handling
+;; TODO: handling of events which not match any route
 ;;
 
 


(defn to-json-format-wrapper
  "a wrapper which convert the :message from a clojure data structure
   into ajson formatted string."
  [handler]
  (fn [values]
    (handler (map #(update % :message to-json) values))))

                       :partition 0
                       :message (to-json m)})))))

  (def ingest
    (doall
     (->> (repeatedly
           (fn []
             {:timestamp (System/currentTimeMillis)
              :eventName "test"
              :sourceId (rand-nth ["d1" "d2" "d3"])
              :action (rand-int 100)}))
          (take 10)
          (map (fn [x]
                 {:topic "ingestion"
                  :key   (:sourceId x)
                  :partition 0
                  :message x}))
          (map #(update % :message to-json)))))

  (def events (concat txlog ingest))

  (def cmp (component/start (make-samsara-core config)))
  (reset! (:output-collector cmp) (fn [e] (doseq [x e] (prn "OUTPUT:" x)) ))

  (build-routes cmp)

  (build-routes-for-stream cmp :ingestion)

  (-> cmp :global-stores)

  (time ((dispatch-group-by
          (build-routes cmp)) events))

  )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
