Class: KubeMQ::CQ::QueryResponseMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/kubemq/cq/query_response_message.rb

Overview

Outbound response to a received query, sent via KubeMQ::CQClient#send_response.

Construct from the fields of a QueryReceived — copy id to request_id and reply_channel — then set #executed, #body, and optionally #cache_hit.

Examples:

Respond to a query

response_msg = KubeMQ::CQ::QueryResponseMessage.new(
  request_id: received_query.id,
  reply_channel: received_query.reply_channel,
  executed: true,
  body: '{"name": "Alice", "age": 30}'
)
client.send_response(response_msg)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id:, reply_channel:, executed:, error: nil, body: nil, metadata: nil, tags: nil, client_id: nil, cache_hit: false) ⇒ QueryResponseMessage

Returns a new instance of QueryResponseMessage.

Parameters:

  • request_id (String)

    the original query's request ID (required)

  • reply_channel (String)

    response channel from KubeMQ::CQ::QueryReceived#reply_channel (required)

  • executed (Boolean)

    whether the query was executed (required)

  • error (String, nil) (defaults to: nil)

    error description on failure

  • body (String, nil) (defaults to: nil)

    response payload

  • metadata (String, nil) (defaults to: nil)

    response metadata

  • tags (Hash{String => String}, nil) (defaults to: nil)

    key-value tags

  • client_id (String, nil) (defaults to: nil)

    responder's client ID

  • cache_hit (Boolean) (defaults to: false)

    whether this response is from cache (default: false)



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kubemq/cq/query_response_message.rb', line 53

def initialize(request_id:, reply_channel:, executed:, error: nil, body: nil,
               metadata: nil, tags: nil, client_id: nil, cache_hit: false)
  @request_id = request_id
  @reply_channel = reply_channel
  @executed = executed
  @error = error
  @body = body
   = 
  @tags = tags || {}
  @client_id = client_id
  @cache_hit = cache_hit
end

Instance Attribute Details

#bodyString?

Returns response payload.

Returns:

  • (String, nil)

    response payload



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#cache_hitBoolean

Returns whether this response should be cached.

Returns:

  • (Boolean)

    whether this response should be cached



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#client_idString?

Returns responder's client identifier.

Returns:

  • (String, nil)

    responder's client identifier



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#errorString?

Returns error description if execution failed.

Returns:

  • (String, nil)

    error description if execution failed



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#executedBoolean

Returns whether the query was executed successfully.

Returns:

  • (Boolean)

    whether the query was executed successfully



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#metadataString?

Returns response metadata.

Returns:

  • (String, nil)

    response metadata



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#reply_channelString

Returns the channel to send the response on.

Returns:

  • (String)

    the channel to send the response on



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit

#request_idString

Returns the original query's request identifier.

Returns:

  • (String)

    the original query's request identifier



41
42
43
# File 'lib/kubemq/cq/query_response_message.rb', line 41

def request_id
  @request_id
end

#tagsHash{String => String}

Returns user-defined key-value tags.

Returns:

  • (Hash{String => String})

    user-defined key-value tags



41
42
# File 'lib/kubemq/cq/query_response_message.rb', line 41

attr_accessor :request_id, :reply_channel, :client_id, :executed,
:error, :body, :metadata, :tags, :cache_hit