I recently ran into a requirement where a Google Cloud Function (GCF) seemed a good fit.
I wanted to use Clojure for this, at least as a first cut, but the examples I found
were centered around ClojureScript/NodeJS, which wound up being a non-starter
for various boring reasons. Googling about turned up essentially nothing about
how to use JVM Clojure for this purpose. The GCF story for Java is about as
easy as it can get, just implement a known interface, uberjar,
and deploy with the gcloud
tool.
My first attempt in Clojure used gen-class
, but deployment resulted in this
exception:
"Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Namespace.<init>(Namespace.java:34)
at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
at clojure.lang.Var.internPrivate(Var.java:156)
at ck.proxysql_notifier.<clinit>(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.google.cloud.functions.invoker.NewHttpFunctionExecutor.forClass(NewHttpFunctionExecutor.java:51)
at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:243)
at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:129)
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
at clojure.lang.RT.load(RT.java:462)
at clojure.lang.RT.load(RT.java:424)
at clojure.lang.RT.<clinit>(RT.java:338)
... 11 more"