clients

package
v1.1.0-3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConnectTimeout = 10000
	DefaultTimeout        = 10000
	DefaultRetriesCount   = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureFunctionClient

type AzureFunctionClient struct {
	// The HTTP client.
	Client *http.Client
	// The Azure Function connection parameters
	Connection *azureconn.AzureFunctionConnectionParams
	// The number of retries.
	Retries int
	// The default headers to be added to every request.
	Headers *cdata.StringValueMap
	// The connection timeout in milliseconds.
	ConnectTimeout int
	// The invocation timeout in milliseconds.
	Timeout int
	// The remote service uri which is calculated on open.
	Uri string
	// The connection resolver.
	ConnectionResolver *azureconn.AzureFunctionConnectionResolver
	// The dependency resolver.
	DependencyResolver *crefer.DependencyResolver

	// The logger.
	Logger *clog.CompositeLogger
	// The performance counters.
	Counters *ccount.CompositeCounters
	// The tracer.
	Tracer *ctrace.CompositeTracer
}

Abstract client that calls Azure Functions.

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 t
	    - 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 connection
	- *:credential-store:*:*:1.0	(optional) Credential stores to resolve credentials

see AzureFunction, CommandableAzureClient

Example:
	type MyAzureFunctionClient struct {
		*clients.AzureFunctionClient
	}

	func NewMyAzureFunctionClient() *MyAzureFunctionClient {
		return &MyAzureFunctionClient{
			AzureFunctionClient: azureclient.NewAzureFunctionClient(),
		}
	}

	func (c *MyAzureFunctionClient) GetData(ctx context.Context, id string) MyData {
		timing := c.Instrument(ctx, "myclient.get_data")

		response, err := c.Call(ctx, "get_data", data.NewAnyValueMapFromTuples("id", dummyId))

		defer timing.EndTiming(ctx, err)
		return rpcclients.HandleHttpResponse[MyData](response, cctx.GetTraceId(ctx))
	}

	...

	client := NewMyAzureFunctionClient()
	client.Configure(config.NewConfigParamsFromTuples(
		"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.GetData("123", "1")

func NewAzureFunctionClient

func NewAzureFunctionClient() *AzureFunctionClient

Creates new instance of AzureFunctionClient

func (*AzureFunctionClient) AddFilterParams

func (c *AzureFunctionClient) AddFilterParams(params *cdata.StringValueMap, filter *cquery.FilterParams) *cdata.StringValueMap

AddFilterParams method are adds filter parameters (with the same name as they defined) to invocation parameter map.

Parameters:
	- params  *cdata.StringValueMap      invocation parameters.
	- filter  *cdata.FilterParams     (optional) filter parameters
Returns: invocation parameters with added filter parameters.

func (*AzureFunctionClient) AddPagingParams

func (c *AzureFunctionClient) AddPagingParams(params *cdata.StringValueMap, paging *cquery.PagingParams) *cdata.StringValueMap

AddPagingParams method are adds paging parameters (skip, take, total) to invocation parameter map. Parameters:

  • params invocation parameters.
  • paging (optional) paging parameters

Return invocation parameters with added paging parameters.

func (*AzureFunctionClient) Call

Performs Azure Function invocation. Parameters:

  • ctx context.Context execution context to trace execution through call chain.
  • cmd an action name to be called.
  • args action arguments

Returns action result.

func (*AzureFunctionClient) Close

func (c *AzureFunctionClient) Close(ctx context.Context) error

Closes component and frees used resources. Parameters:

  • ctx context.Context execution context to trace execution through call chain.

func (*AzureFunctionClient) Configure

func (c *AzureFunctionClient) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure object by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config: ConfigParams configuration parameters to be set.

func (*AzureFunctionClient) Instrument

Instrument method are adds instrumentation to log calls and measure call time. It returns a services.InstrumentTiming object that is used to end the time measurement.

Parameters:
	- ctx context.Context execution context to trace execution through call chain.
	- name string a method name.
Returns: services.InstrumentTiming object to end the time measurement.

func (*AzureFunctionClient) IsOpen

func (c *AzureFunctionClient) IsOpen() bool

IsOpen Checks if the component is opened.

Returns: bool true if the component has been opened and false otherwise.

func (*AzureFunctionClient) Open

Open opens the component.

Parameters:
	- ctx context.Context execution context to trace execution through call chain.
Return: error

func (*AzureFunctionClient) SetReferences

func (c *AzureFunctionClient) SetReferences(ctx context.Context, references crefer.IReferences)

SetReferences sets references to dependent components.

see IReferences
Parameters:
	- ctx context.Context
	- references IReferences references to locate the component dependencies.

type CommandableAzureFunctionClient

type CommandableAzureFunctionClient struct {
	*AzureFunctionClient
	// contains filtered or unexported fields
}

Abstract client that calls commandable Azure Functions.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as action determined by "cmd" parameter.

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 connection
	- *:credential-store:*:*:1.0	(optional) Credential stores to resolve credentials

see AzureFunction

Exammple:
	type MyCommandableAzureClient struct {
		*clients.CommandableAzureFunctionClient
	}

	func NewMyCommandableAzureClient() *MyCommandableAzureClient {
		return &MyCommandableAzureClient{
			CommandableAzureFunctionClient: azureclient.NewCommandableAzureFunctionClient(),
		}
	}

	func (c *MyCommandableAzureClient) GetData(ctx context.Context, id string) MyData {
		response, err := c.CallCommand(ctx, "dummies.get_dummies", cdata.NewAnyValueMapFromTuples("id", id))
		if err != nil {
			return MyData{}, err
		}

		return rpcclient.HandleHttpResponse[MyData](response, cctx.GetTraceId(ctx))
	}

	...
	client := NewMyCommandableAzureClient()
	client.Configure(config.NewConfigParamsFromTuples(
		"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.GetData("123", "1")
	...

func NewCommandableAzureFunctionClient

func NewCommandableAzureFunctionClient(name string) *CommandableAzureFunctionClient

Creates a new instance of this client. Parameters:

  • name a service name.

func (*CommandableAzureFunctionClient) CallCommand

Calls a remote action in Azure Function. The name of the action is added as "cmd" parameter to the action parameters. Parameters:

  • ctx context.Context execution context to trace execution through call chain.
  • cmd an action name
  • params command parameters.

Returns action result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL