AzureFunctionClient

Abstract client that calls Azure Functions.

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
  • 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

_client

The HTTP client.

_client: requests.Session

_connectTimeout

The connection timeout in milliseconds.

_connectTimeout: int = 10000

_connection

The Azure Function connection parameters

_connection: AzureConnectionParams

_connection_resolver

The connection resolver.

_connectionResolver: AzureConnectionResolver

_counters

Performance counters.

_counters: CompositeCounters

_dependency_resolver

Dependencies resolver.

_dependency_resolver: DependencyResolver

_headers

The default headers to be added to every request.

_headers: dict = {}

_logger

Logger.

_logger: CompositeLogger

_timeout

The invocation timeout in milliseconds.

_timeout: number = 10000

_tracer

The tracer.

_tracer: CompositeTracer

_uri

The remote service uri which is calculated on open.

_uri: string

Instance methods

_call

Calls a Azure Function action.

_call(cmd: str, correlation_id: Optional[str], params: dict = {}): Any

  • cmd: str - an action name to be called.
  • correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
  • params: dict - (optional) action parameters.
  • returns: Any - action result.

close

Closes component and frees used resources.

close(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.

configure

Configures component by passing configuration parameters.

configure(config: ConfigParams)

  • 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.

_instrument(correlation_id: Optional[str], name: str): InstrumentTiming

  • correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
  • name: str - a method name.
  • return: InstrumentTiming - object to end the time measurement.

_invoke

Performs Azure Function invocation.

_invoke<T>(cmd: str, correlation_id: Optional[str], args: dict): Any

  • cmd: srt - action result.
  • correlation_id: Optional[str] - action result.
  • args: dict - action result.
  • returns: Any - action result.

is_open

Checks if the component is opened.

is_open(): bool

  • returns: bool - true if the component has been opened and false otherwise.

open

Opens the component.

open(correlation_id: Optional[str])

  • correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.

set_references

Sets references to dependent components.

set_references(references: IReferences)

  • references: IReferences - references to locate the component dependencies.

Examples

class MyAzureFunctionClient(AzureFunctionClient, IMyClient):
    ...
    def get_data(self, correlation_id: Optional[str], id: str) -> MyData:
        timing = self._instrument(correlation_id, 'myclient.get_data')
        result = self._call('get_data', correlation_id, {'id': id}
        timing.end_timing()
        return result
    ...

client = MyAzureFunctionClient()

client.open("123")

client.configure(ConfigParams.from_tuples(
    "connection.uri", "http://myapp.azurewebsites.net/api/myfunction",
    "connection.protocol", "http",
    "connection.app_name", "myapp",
    "connection.function_name", "myfunction"
    "credential.auth_code", "XXXX"
))

result = client.get_data('123', '1')

See also