Last active
October 7, 2022 19:15
-
-
Save hindol/78e9aa0147b6ebffe7b82d2c3fe99fc1 to your computer and use it in GitHub Desktop.
Writing Azure Functions in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check hindol/clj-fn@d3baaae for an alternative Maven based approach to calling Clojure code from Azure Functions.