client

package module
v0.0.0-...-b70667e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 24 Imported by: 1

README

Client library for Agent Communication API.

Documentation

Overview

Package client is an AgentCommunication client library.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DebugLogging enables debug logging.
	DebugLogging = false
	// ErrConnectionClosed is an error indicating that the connection was closed by the caller.
	ErrConnectionClosed = errors.New("connection closed")
	// ErrMessageTimeout is an error indicating message send timed out.
	ErrMessageTimeout = errors.New("timed out waiting for response")
	// ErrResourceExhausted is an error indicating that the server responded to the send with
	// ResourceExhausted.
	ErrResourceExhausted = errors.New("resource exhausted")
	// ErrGettingInstanceToken is an error indicating that the instance token could not be retrieved.
	ErrGettingInstanceToken = errors.New("error getting instance token")
)

Functions

func NewClient

func NewClient(ctx context.Context, regional bool, opts ...option.ClientOption) (*agentcommunication.Client, error)

NewClient creates a new agent communication grpc client. Caller must close the returned client when it is done being used to clean up its underlying connections.

func SendAgentMessage

func SendAgentMessage(ctx context.Context, channelID string, client *agentcommunication.Client, msg *acpb.MessageBody) (*acpb.SendAgentMessageResponse, error)

SendAgentMessage sends a message to the client. This is equivalent to sending a message via StreamAgentMessages with a single message and waiting for the response.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection is an AgentCommunication connection.

func CreateConnection

func CreateConnection(ctx context.Context, channelID string, regional bool, opts ...option.ClientOption) (*Connection, error)

CreateConnection creates a new connection. DEPRECATED: Use NewConnection instead.

func NewConnection

func NewConnection(ctx context.Context, channelID string, client *agentcommunication.Client) (*Connection, error)

NewConnection creates a new streaming connection. Caller is responsible for calling Close() on the connection when done, certain errors will cause the connection to be closed automatically. The passed in client will not be closed and can be reused.

func (*Connection) Close

func (c *Connection) Close()

Close the connection.

func (*Connection) MessageBandwidthLimit

func (c *Connection) MessageBandwidthLimit() int

MessageBandwidthLimit returns the message bandwidth limit (in bytes/minute) for the connection.

func (*Connection) MessageRateLimit

func (c *Connection) MessageRateLimit() int

MessageRateLimit returns the message limit (in messages/minute) for the connection.

func (*Connection) Receive

func (c *Connection) Receive() (*acpb.MessageBody, error)

Receive messages, Receive should be called continuously for the life of the stream connection, any delay in Receive when there are queued messages will cause the server to disconnect the stream. This means handling the MessageBody from Receive should not be blocking, offload message handling to another goroutine and immediately call Receive again.

func (*Connection) SendMessage

func (c *Connection) SendMessage(msg *acpb.MessageBody) error

SendMessage sends a message to the client. Will automatically retry on message timeout (temporary disconnects) and in the case of ResourceExhausted with a backoff. Because retries are limited the returned error can in some cases be one of ErrMessageTimeout or ErrResourceExhausted, in which case send should be retried by the caller.

Directories

Path Synopsis
Example usage of the ACS client library.
Example usage of the ACS client library.
Package agentcommunication is an auto-generated package for the Agent Communication API.
Package agentcommunication is an auto-generated package for the Agent Communication API.

Jump to

Keyboard shortcuts

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