Class: KubeMQ::CQ::QueryResponse

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

Overview

Response returned by KubeMQ::CQClient#send_query after a subscriber processes the query.

Contains the response #body and #metadata, plus a #cache_hit flag indicating whether the response was served from the broker's server-side cache.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, request_id:, executed:, error: nil, timestamp: 0, tags: nil, body: nil, metadata: nil, cache_hit: false) ⇒ QueryResponse

Returns a new instance of QueryResponse.

Parameters:

  • client_id (String)

    responder's client ID

  • request_id (String)

    original request ID

  • executed (Boolean)

    whether the query was executed

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

    error description on failure

  • timestamp (Integer) (defaults to: 0)

    response timestamp (default: 0)

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

    key-value tags

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

    response payload

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

    response metadata

  • cache_hit (Boolean) (defaults to: false)

    whether served from cache (default: false)



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kubemq/cq/query_response.rb', line 45

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

Instance Attribute Details

#bodyString? (readonly)

Returns response payload.

Returns:

  • (String, nil)

    response payload



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#cache_hitObject (readonly)

Returns the value of attribute cache_hit.



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#client_idString (readonly)

Returns the responder's client identifier.

Returns:

  • (String)

    the responder's client identifier



33
34
35
# File 'lib/kubemq/cq/query_response.rb', line 33

def client_id
  @client_id
end

#errorString? (readonly)

Returns error description if execution failed.

Returns:

  • (String, nil)

    error description if execution failed



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#executedBoolean (readonly)

Returns true if the query was executed successfully.

Returns:

  • (Boolean)

    true if the query was executed successfully



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#metadataString? (readonly)

Returns response metadata.

Returns:

  • (String, nil)

    response metadata



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#request_idString (readonly)

Returns the original query request identifier.

Returns:

  • (String)

    the original query request identifier



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#tagsHash{String => String} (readonly)

Returns user-defined key-value tags.

Returns:

  • (Hash{String => String})

    user-defined key-value tags



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit

#timestampInteger (readonly)

Returns broker-assigned response timestamp (Unix nanoseconds).

Returns:

  • (Integer)

    broker-assigned response timestamp (Unix nanoseconds)



33
34
# File 'lib/kubemq/cq/query_response.rb', line 33

attr_reader :client_id, :request_id, :executed, :error, :timestamp,
:tags, :body, :metadata, :cache_hit