Connecting this library to a project on Kotlin allows you to deploy the corresponding artifact to extremum as a serverless feature package, allowing you to call package functions through the platform API and assign them as signal handlers and storage triggers. Each function is framed as a class in the project.
io.extremum:functions-api:<version>
import io.extremum.common.annotation.function.FunctionPackage
@SpringBootApplication
@FunctionPackage(name = "my-package")
class MyFunctionsPackageApplication
where my-package
- name of the function package to be created
Name Requirements:
@Function
;BasePackageFunction
, must implement its methods onStorageTriggerи
onSignal`;public
type field Context
with annotation @FunctionContext
;Example of a function
import io.extremum.common.annotation.function.Function
import io.extremum.common.annotation.function.FunctionContext
import io.extremum.common.annotation.function.FunctionMethod
import io.extremum.functions.api.function.BasePackageFunction
import io.extremum.functions.api.function.model.Context
import io.extremum.functions.api.function.model.SignalParameters
import io.extremum.functions.api.function.model.StorageTriggerParameters
@Function(name = "number-func")
class NumberFunction : BasePackageFunction {
@FunctionContext
val context = Context.EMPTY
/**
* Executed when querying a package function (main function method)
*/
@FunctionMethod
fun launch(params: Map<String, Any?>): Int {
//at the time of the call, headers from the request body are filled in the context
//method implementation
}
/**
* Executed when a message is received from an Object Storage trigger
*/
override suspend fun onStorageTrigger(parameters: StorageTriggerParameters) {
// headers are filled in the context at the time of the call
// method implementation
}
/**
* Executed when a signal is received
*/
override suspend fun onSignal(parameters: SignalParameters) {
//at the time of the call, headers are filled in the context
//method implementation
}
// other methods
}
Function name requirements:
The function name (in the number-func
example) may not be the same as the name of the function class.
Function name requirements are the same as package name requirements.
Function names must be unique within the same package.
Requirements for the main method of the function (with annotation @FunctionMethod
):
The method marked with the annotation @ FunctionMethod
(or the main method) must have only one in the function.
Method must accept one and only one parameter. It can be its own object, map, collection, number, etc.
The parameter can be nullable
.
The method can return any value, including 'nullable', or not return at all if not required.
Or to container environment variables
xAppId=
apiBaseUrl=
serviceClientId=
serviceClientSecret=
keycloakUri=
groundUri=
After you connect the library to the project, build the project, and run it, it will accept HTTP requests as follows:
POST http://localhost:8080/
Content-Type: application/json
where http://localhost:8080/
- The URL of the server with the application.
The body depends on the call assignment. The following queries are available
When the function is called directly, the body has the form
{
"parameters": {
"name": "Jack",
"age": 23
},
"context": {
"headers": {
"Authorization": "Bearer ",
"x-app-id": "appid"
},
"package": "my-package",
"function": "number-func"
}
}
Type parameters
must match the parameter type of the main method of function number-func
.
context.package
specifies the name of the called package. In context.function
- the name of the called function.
When a function is called, the specified context is populated in the context
field of the function and the main method of the function with the parameters passed is called.
The response to the query will be the resulting value of the function's main method.
{
"messages": [
{
"event_metadata": {
"event_id": "bb1dd06d-a82c-49b4-af98-d8e0c5a1d8f0",
"event_type": "yandex.cloud.events.storage.ObjectDelete",
"created_at": "2019-12-19T14:17:47.847365Z",
"tracing_context": {
"trace_id": "dd52ace79c62892f"
}
},
"details": {
"bucket_id": "s3-for-trigger",
"object_id": "dev/0_15a775_972dbde4_orig12.jpg"
}
}
]
}
Where messages
is the list of messages.
For each message, it is determined which package functions are subscribed to it.
Then, for each of these functions, the onStorageTrigger
method is called with the messages it needs.
{
"messages": [
{
"event_metadata": {
"event_id": "cce76685-5828-4304-a83d-95643c0507a0",
"event_type": "yandex.cloud.events.messagequeue.QueueMessage",
"created_at": "2019-09-24T00:54:28.980441Z"
},
"details": {
"queue_id": "yrn:yc:ymq:ru-central1:21i6v06sqmsaoeon7nus:event-queue",
"message": {
"message_id": "cce76685-5828-4304-a83d-95643c0507a0",
"md5_of_body": "d29343907090dff4cec4a9a0efb80d20",
"body": "message body",
"attributes": {
"SentTimestamp": "1569285804456"
}
}
}
}
]
}
Where messages
is the list of messages.
For each message, it is determined which package functions are subscribed to it.
Then, for each of these functions, the onSignal
method is called with the messages it needs.