Provides a very simply event bus using core.async
to allow publishing and subscribing to interesting topics
happening throughout the tservice system in a decoupled way. It's based on metabase.events
.
Internal Events: The most appropriate way to initialize event listeners in any tservice.events.*
namespace
(you can use setup-custom-namespace
to change it) is to implement the
events-init
function which accepts zero arguments. This function is dynamically resolved and called exactly once
when the application goes through normal startup procedures. Inside this function you can do any work needed and add
your events subscribers to the bus as usual via start-event-listener!
.
Examples:
; Call these code in app entrypoint.
;; First Step
(setup-custom-namespace "tservice" :sub-ns "events")
;; Second Step (Call it when the app instance is launched.)
(initialize-events!)
; Defined in each event.
;; Define event handler
(defn- test-handler!
[{:keys [test-content]}]
(println test-content))
;; Define events-init function.
(def events-init
"Automatically called during startup; start event listener for test event."
(make-events-init "test" test-handler!))
; When you need to trigger an event, call this code
(publish-event! "test" {:test-content "This is a test."})
External Events: If you use the event bus in plugin, you need to use make-events-init
to
generate event initializer and initialize the event in plugin configuration file.
When the above setting is successful, you can use publish-event! to trigger an event.
Provides a very simply event bus using `core.async` to allow publishing and subscribing to interesting topics happening throughout the tservice system in a decoupled way. It's based on `metabase.events`. ## Regarding Events Initialization: Internal Events: The most appropriate way to initialize event listeners in any `tservice.events.*` namespace (you can use [[setup-custom-namespace]] to change it) is to implement the `events-init` function which accepts zero arguments. This function is dynamically resolved and called exactly once when the application goes through normal startup procedures. Inside this function you can do any work needed and add your events subscribers to the bus as usual via `start-event-listener!`. Examples: ```clojure ; Call these code in app entrypoint. ;; First Step (setup-custom-namespace "tservice" :sub-ns "events") ;; Second Step (Call it when the app instance is launched.) (initialize-events!) ; Defined in each event. ;; Define event handler (defn- test-handler! [{:keys [test-content]}] (println test-content)) ;; Define events-init function. (def events-init "Automatically called during startup; start event listener for test event." (make-events-init "test" test-handler!)) ; When you need to trigger an event, call this code (publish-event! "test" {:test-content "This is a test."}) ``` External Events: If you use the event bus in plugin, you need to use [[make-events-init]] to generate event initializer and initialize the event in plugin configuration file. When the above setting is successful, you can use publish-event! to trigger an event.
(initialize-events!)
Initialize the asynchronous internal events system. You need to call it when the app is launched.
Initialize the asynchronous internal events system. You need to call it when the app is launched.
(make-events-init event-name event-handler)
Generate event initializer.
Generate event initializer.
(object->model-id topic object)
Determine the appropriate model_id
(if possible) for a given OBJECT.
Determine the appropriate `model_id` (if possible) for a given OBJECT.
(object->user-id object)
Determine the appropriate user_id
(if possible) for a given OBJECT.
Determine the appropriate `user_id` (if possible) for a given OBJECT.
(publish-event! topic event-item)
Publish an item into the events stream. Returns the published item to allow for chaining.
Publish an item into the events stream. Returns the published item to allow for chaining.
(setup-custom-namespace namespace & {:keys [sub-ns] :or {sub-ns "events"}})
(start-event-listener! topics channel handler-fn)
Initialize an event listener which runs on a background thread via go-loop
.
Initialize an event listener which runs on a background thread via `go-loop`.
(topic->model topic)
Determine a valid model
identifier for the given TOPIC.
Determine a valid `model` identifier for the given TOPIC.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close