Implements: IOpenable, IConfigurable, IReferenceable
Description
When making calls “cmd” parameter determines which what action shall be called, while other parameters are passed to the action itself.
Configuration parameters
- connections:
- uri: (optional) full connection string or use protocol, app_name and function_name to build
- protocol: (optional) connection protocol
- app_name: (optional) Azure Function application name
- function_name: (optional) Azure Function name
- options:
- retries: number of retries (default: 3)
- connect_timeout: connection timeout in milliseconds (default: 10 sec)
- timeout: invocation timeout in milliseconds (default: 10 sec)
- credentials:
- auth_code: Azure Function auth code if use custom authorization provide empty string
References
- *:logger:*:*:1.0 - (optional) ILogger components to pass log messages.
- *:counters:*:*:1.0 - (optional) ICounters components to pass collected measurements.
- *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connections.
- *:credential-store:*:*:1.0 - (optional) Credential stores to resolve credentials.
Fields
Instance methods
call
Calls a Azure Function action.
Future call(String cmd, IContext? context, params)
- cmd: string - an action name to be called.
- context: IContext - (optional) a context to trace execution through a call chain.
- params: (optional) action parameters.
- returns: Future - action result.
close
Closes component and frees used resources.
Future close(IContext? context) async
- context: IContext - (optional) a context to trace execution through a call chain.
configure
Configures component by passing configuration parameters.
void configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
instrument
Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.
InstrumentTiming instrument(IContext? context, String name)
- correlationId: string - (optional) transaction id to trace execution through call chain.
- name: string - a method name.
- return: InstrumentTiming - object to end the time measurement.
invoke
Performs Azure Function invocation.
Future invoke(String? cmd, IContext? context, Map args) async
- cmd: string - action result.
- context: IContext - (optional) a context to trace execution through a call chain.
- args: any - action result.
- returns: Promise<T> - action result.
isOpen
Checks if the component is opened.
bool isOpen()
- returns: boolean - true if the component has been opened and false otherwise.
open
Opens the component.
Future open(IContext? context) async
- context: IContext - (optional) a context to trace execution through a call chain.
setReferences
Sets references to dependent components.
void setReferences(IReferences references)
- references: IReferences - references to locate the component dependencies.
Examples
class MyAzureFunctionClient extends AzureFunctionClient implements IMyClient {
...
Future<MyData> getData(IContext? context, String id) async {
var timing = this.instrument(context, 'myclient.get_data');
var result = await call('get_data', context, { id: id });
timing.endTiming();
return result;
}
...
}
var client = MyAzureFunctionClient();
client.configure(ConfigParams.fromTuples([
"connection.uri", "http://myapp.azurewebsites.net/api/myfunction",
"connection.protocol", "http",
"connection.app_name", "myapp",
"connection.function_name", "myfunction"
"credential.auth_code", "XXXX"
]));
var data = client.getData(Context.fromTraceId('123'), '1');