communication

package
v0.0.0-...-e5ec0a4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package communication provides capability for Google Cloud Agents to communicate with Google Cloud Service Providers via Agent Communication Service (ACS).

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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.

func SendStatusMessage

func SendStatusMessage(ctx context.Context, operationID string, body *anypb.Any, status string, lroState string, conn *client.Connection) error

SendStatusMessage sends a status message 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.

Jump to

Keyboard shortcuts

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