Skip to content

Instantly share code, notes, and snippets.

@hindol
Last active October 7, 2022 19:15
Show Gist options
  • Save hindol/78e9aa0147b6ebffe7b82d2c3fe99fc1 to your computer and use it in GitHub Desktop.
Save hindol/78e9aa0147b6ebffe7b82d2c3fe99fc1 to your computer and use it in GitHub Desktop.
Writing Azure Functions in Clojure
(ns com.github.hindol.clj-fn.core
(:import
(com.microsoft.azure.functions ExecutionContext
HttpRequestMessage
HttpResponseMessage
OutputBinding)
(com.microsoft.azure.functions.annotation FunctionName
HttpTrigger
QueueOutput)))
;; Bug: https://clojure.atlassian.net/browse/CLJ-2269
;; Must fully qualify type hints on definterface.
(definterface Functional
(^com.microsoft.azure.functions.HttpResponseMessage
run
[^com.microsoft.azure.functions.HttpRequestMessage
request
^com.microsoft.azure.functions.OutputBinding
message
^com.microsoft.azure.functions.ExecutionContext
context]))
(deftype Function []
Functional
(^{:tag HttpResponseMessage
FunctionName "HttpExample"}
run
[this
^{:tag HttpRequestMessage
HttpTrigger {:name "req"
:methods [HttpMethod/GET HttpMethod/POST]
:authLevel AuthorizationLevel/ANONYMOUS}}
request
^{:tag OutputBinding
QueueOutput {:name "msg"
:queueName "outqueue"
:connection "AzureWebJobsStorage"}}
message
^ExecutionContext
context]
42))
package com.github.hindol.clj_fn.core;
import clojure.lang.*;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.*;
public final class Function implements Functional, IType
{
public static final Object const__0;
public static IPersistentVector getBasis() {
return Tuple.create();
}
@FunctionName("HttpExample")
public HttpResponseMessage run(@HttpTrigger(name = "req", methods = { HttpMethod.GET, HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) final HttpRequestMessage request, @QueueOutput(name = "msg", queueName = "outqueue", connection = "AzureWebJobsStorage") final OutputBinding message, final ExecutionContext context) {
return (HttpResponseMessage)Function.const__0;
}
static {
const__0 = 42L;
}
}
package com.github.hindol.clj_fn.core;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.OutputBinding;
public interface Functional {
HttpResponseMessage run(HttpRequestMessage paramHttpRequestMessage, OutputBinding paramOutputBinding, ExecutionContext paramExecutionContext);
}
@hindol
Copy link
Author

hindol commented Apr 16, 2020

Check hindol/clj-fn@d3baaae for an alternative Maven based approach to calling Clojure code from Azure Functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment