Documentation
¶
Overview ¶
Package communication provides capability for Google Cloud Agents to communicate with Google Cloud Service Providers via Agent Communication Service (ACS).
Index ¶
- Variables
- func Communicate(ctx context.Context, endpoint string, channel string, ...) error
- func EstablishACSConnection(ctx context.Context, endpoint string, channel string) *client.Connection
- func Listen(ctx context.Context, conn *client.Connection, ...) error
- func SendAgentMessage(ctx context.Context, messageKey string, messageType string, body *anypb.Any, ...) error
- func SendStatusMessage(ctx context.Context, operationID string, body *anypb.Any, status string, ...) error
- type ConnectionHandler
- type MsgHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReceive indicates a failure to receive a message from ACS. ErrReceive = errors.New("failed to receive message from ACS") // ErrHandler indicates that the connection handler failed to process a message. ErrHandler = errors.New("connection handler failed") )
var SendMessage = func(c *client.Connection, msg *acpb.MessageBody) error {
return c.SendMessage(msg)
}
SendMessage is a function that sends a message to ACS. It is exported for testing purposes.
Functions ¶
func Communicate ¶
func Communicate(ctx context.Context, endpoint string, channel string, messageHandler MsgHandlerFunc, cloudProperties *metadataserver.CloudProperties) error
Communicate creates ACS connection and enters a loop to receive messages. It is designed for synchronous use cases where LROs are not required. Communicate invokes the provided `messageHandler` to process the message. Once the handler returns, it automatically sends a single final "done" status message with the result. This function is left for backward compatibility with existing code. New code should use Listen() directly.
func EstablishACSConnection ¶
func EstablishACSConnection(ctx context.Context, endpoint string, channel string) *client.Connection
EstablishACSConnection establishes a connection to ACS. "endpoint" is the endpoint and will often be an empty string. "channel" is the registered channel name to be used for communication between the agent and the service provider.
func Listen ¶
func Listen(ctx context.Context, conn *client.Connection, connectionHandler ConnectionHandler, cloudProperties *metadataserver.CloudProperties) error
Listen enters a loop to receive messages from an established ACS connection, delegating message processing to the provided connectionHandler. Passing the connection to the handler gives it full control over the response lifecycle, allowing it to: 1. Send multiple status updates (e.g., "running" then "done") for LROs. 2. Perform work asynchronously in the background without blocking the listener loop.
func SendAgentMessage ¶
func SendAgentMessage(ctx context.Context, messageKey string, messageType string, body *anypb.Any, conn *client.Connection) error
SendAgentMessage sends a message from the agent to the service provider via ACS. "messageKey" is the label key to be used for the message. "messageType" is the label value of the message. "body" is the body of the message. "conn" is the connection to ACS.
Types ¶
type ConnectionHandler ¶
type ConnectionHandler func(context.Context, *acpb.MessageBody, *client.Connection, *metadataserver.CloudProperties) error
ConnectionHandler is the function that the agent will use to handle incoming messages with access to the ACS connection.
type MsgHandlerFunc ¶
type MsgHandlerFunc func(context.Context, *anypb.Any, *metadataserver.CloudProperties) (*anypb.Any, error)
MsgHandlerFunc is the function that the agent will use to handle incoming messages.