InjectTheDriver driver implementations for RabbitMQ.
This library defines
a lambda-kube module:
rabbit-drivers.lk/module
. Add this module to your project:
(ns my-app
(:require [rabbit-drivers.lk :as rmqd]
;; ...
))
;; ...
(def config {:use-single-rabbitmq true
;; ...
})
(defn -main []
(-> (lk/injector)
;; ...
(rmqd/module)
;; ...
(lk/get-deployable config)
;; ...
))
The key :use-single-rabbitmq
in the configuration will create a
single-node RabbitMQ cluster. The value (true
in the example above)
is ignored.
It contributes a resource named :event-broker
.
Within modules that define (micro-)services that depend on RabbitMQ,
add :event-broker
as a dependency. To inject drivers into a
container,
use
lku/inject-driver:
(defn my-module [$]
(-> $
;; ...
(lk/rule :my-microservice
[:event-broker :other :deps]
(fn [event-broker other deps]
(-> (lk/pod :my-microservice {:my :lables})
(lk/add-container :my-cont "my-image")
;; Force this pod to wait for the amqp port to be
;; available befoe launching
(lku/wait-for-service-port event-broker :amqp)
;; Inject the QueueService and PubSubService drivers into the my-cont container
(lk/update-container :my-cont lku/inject-driver QueueService event-broker)
(lk/update-container :my-cont lku/inject-driver PubSubService event-broker)
;; ...
)))))
Inside the microservice code itself, the
injectthedriver.DriverFactory
class can be used to instantiate
driver objects. For example, the following code instantiates a
QueueService
, defines a queue, and publishes on it.
(let [qs (DriverFactory/createDriverFor QueueService)
q (.defineQueue qs "foo")]
(.enqueue q (.getBytes "Hello, World")))
Note that although this code is written in Clojure, this mechanism is Java-compatible, meaning that drivers are usable with from within any JVM language. In Java the above code should look like this:
QueueService qs = (QueueService)DriverFactory.createDriverFor(QueueService.class);
QueueService.Queue q = qs.defineQueue("foo");
q.enqueue("Hello, World".getBytes());
This library consists of two parts:
core
, which defines the drivers, andlk
, which defines the lambda-kube module.While both parts are related, they live on two different levels. The
core
namespace lives within client (micro-)services, while the lk
namespace helps build Kubernetes deployment manifests. The connection
between them is the following:
lein uberjar
in the project directory.rabbit-drivers-uber.jar
, located in the root of this repository.rabbit-drivers-uber.jar
is tracked in this repository, so when committing it and pushing it upstream it is uploaded to GitHub.lk/module
specifies the URL to this uberjar, so that when it is used in an application, the latest driver version is used.Note: The URL being used does not refer to a specific version of the uber-jar, but rather to the latest. One needs to be careful when introducing breaking changes.
To run driver-level tests, use: lein midje :filter -kube
(with or without :autotest
).
To run Kubernetes-level tests:
rabbit-drivers-uber.jar
is updated to the latest driver version, and uploaded to GitHub (git commit
, git push
).kubectl
configured.lein midje :filter kube
.Copyright © 2018 Boaz Rosenan
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close