RPC
KubeMQ Go SDK reference for Commands and Queries, covering request-reply methods, timeouts, and response caching.
Commands and queries implement request–reply over channels. Commands expect a single response; queries return data payloads and support optional response caching.
Commands
SendCommand
func (c *Client) SendCommand(ctx context.Context, command *Command) (*CommandResponse, error)Sends a command and blocks until a response arrives or timeout elapses.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | Overall deadline |
command | *Command | Yes | Channel, body/metadata, SetTimeout, tags |
Returns: *CommandResponse — execution metadata and payload from responder.
SubscribeToCommands
func (c *Client) SubscribeToCommands(ctx context.Context, channel, group string, opts ...SubscribeOption) (*Subscription, error)Receives incoming commands for a service. Use handlers configured via SubscribeOption.
SendCommandResponse
func (c *Client) SendCommandResponse(ctx context.Context, response *CommandReply) errorReplies to a command received in the subscription callback.
Queries
SendQuery
func (c *Client) SendQuery(ctx context.Context, query *Query) (*QueryResponse, error)Sends a query and waits for a typed response. Use SetCacheKey / SetCacheTTL on the Query for server-side cache hints.
SubscribeToQueries
func (c *Client) SubscribeToQueries(ctx context.Context, channel, group string, opts ...SubscribeOption) (*Subscription, error)Subscribes as a query worker; analogous to commands with different protobuf routing.
SendQueryResponse
func (c *Client) SendQueryResponse(ctx context.Context, response *QueryReply) errorReturns data and metadata to the caller of SendQuery.
Message helpers
| Type | Factory | Notes |
|---|---|---|
Command | NewCommand() | Timeout required for server routing |
Query | NewQuery() | Adds cache key/TTL fields |
Quick Usage
cmd := kubemq.NewCommand()
cmd.SetChannel("svc.commands")
cmd.SetBody([]byte("ping"))
cmd.SetTimeout(5 * time.Second)
resp, err := client.SendCommand(ctx, cmd)
if err != nil {
return err
}
_ = resp.ExecutedSee Also
Was this page helpful?