Huawei FunctionGraph
Since Camel 3.11
Only producer is supported
Huawei Cloud FunctionGraph component allows you to integrate with FunctionGraph provided by Huawei Cloud.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-huaweicloud-functiongraph</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Huawei FunctionGraph component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Huawei FunctionGraph endpoint is configured using URI syntax:
hwcloud-functiongraph:operation
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
FunctionGraph url. Carries higher precedence than region parameter based client initialization. | String | ||
Name of the function to invoke. | String | ||
Functions that can be logically grouped together. | default | String | |
Required Cloud project ID. | String | ||
Required FunctionGraph service region. This is lower precedence than endpoint based configuration. | String | ||
Configuration object for cloud service authentication. | ServiceKeys | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Proxy server ip/hostname. | String | ||
Proxy authentication password. | String | ||
Proxy server port. | int | ||
Proxy authentication user. | String | ||
Required Access key for the cloud user. | String | ||
Ignore SSL verification. | false | boolean | |
Required Secret key for the cloud user. | String |
Message Body
The message body at each side of the Huawei FunctionGraph component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| The event of the function, which FunctionGraph takes as a JSON object: a Map, or a JSON object as text, bytes, a stream or a file. A JSON array or another JSON value fails: wrap it in a JSON object. A POJO fails unless its text is JSON: marshal it to JSON first. No body fails. |
Producer output |
| The result of the function as text. When the result is a JSON object with a top-level body field, such as the result of a function behind an API Gateway trigger, the body field: a string as it is, an object or an array as JSON, and no body when the field is null. Otherwise the whole result as it is. No body when the function gives no result. With the CamelHwCloudFgXCffLogType exchange property set, the log of the call is in the CamelHwCloudFgXCffLogs exchange property. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Message properties evaluated by the FunctionGraph producer
| Header | Type | Description |
|---|---|---|
|
| Name of operation to invoke |
|
| Name of function to invoke operation on |
|
| Name of the function package |
|
| Type of log to be returned by FunctionGraph operation |
If the operation, function name, or function package are set, they will override their corresponding query parameter.
Message properties set by the FunctionGraph producer
| Header | Type | Description |
|---|---|---|
|
| Unique log returned by FunctionGraph after processing the request if |
Message body
The body of the message is the event of the function, which FunctionGraph takes as a JSON object. It can be a Map, or a JSON object as a String, bytes, a stream or a file. A JSON array or another JSON value that is not an object fails with an IllegalArgumentException: wrap it in a JSON object, such as {"items": [1, 2, 3]}. Marshal a POJO to JSON first.
After the call, the body of the message is the result of the function as text:
-
When the result is a JSON object with a top-level
bodyfield, such as the result of a function behind an API Gateway trigger ({"statusCode": 200, "headers": {…}, "body": "…"}), the body is that field: a string as it is, an object or an array as JSON. The body is null when the field is null. -
Otherwise, the body is the whole result as it is, such as a JSON object without a
bodyfield, a JSON array or plain text.
Using ServiceKey Configuration Bean
Access key and secret keys are required to authenticate against cloud FunctionGraph service. You can avoid having them being exposed and scattered over in your endpoint uri by wrapping them inside a bean of class org.apache.camel.component.huaweicloud.functiongraph.models.ServiceKeys. Add it to the registry and let Camel look it up by referring the object via endpoint query parameter serviceKeys.
Check the following code snippets:
<bean id="myServiceKeyConfig" class="org.apache.camel.component.huaweicloud.functiongraph.models.ServiceKeys">
<property name="accessKey" value="your_access_key" />
<property name="secretKey" value="your_secret_key" />
</bean> -
Java
-
XML
-
YAML
from("direct:triggerRoute")
.setProperty("CamelHwCloudFgOperation", constant("invokeFunction"))
.setProperty("CamelHwCloudFgFunction", constant("your_function_name"))
.setProperty("CamelHwCloudFgPackage", constant("your_function_package"))
.to("hwcloud-functiongraph:invokeFunction?projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc®ion=cn-north-4&serviceKeys=#myServiceKeyConfig") <route>
<from uri="direct:triggerRoute"/>
<setProperty name="CamelHwCloudFgOperation">
<constant>invokeFunction</constant>
</setProperty>
<setProperty name="CamelHwCloudFgFunction">
<constant>your_function_name</constant>
</setProperty>
<setProperty name="CamelHwCloudFgPackage">
<constant>your_function_package</constant>
</setProperty>
<to uri="hwcloud-functiongraph:invokeFunction?projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4&serviceKeys=#myServiceKeyConfig"/>
</route> - route:
from:
uri: direct:triggerRoute
steps:
- setProperty:
name: CamelHwCloudFgOperation
constant: invokeFunction
- setProperty:
name: CamelHwCloudFgFunction
constant: your_function_name
- setProperty:
name: CamelHwCloudFgPackage
constant: your_function_package
- to:
uri: hwcloud-functiongraph:invokeFunction
parameters:
projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
region: cn-north-4
serviceKeys: "#myServiceKeyConfig"