Class: KubeMQ::CQ::QueryMessage

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

Overview

Outbound query message for the request/reply (with data) pattern.

Construct a QueryMessage and pass it to KubeMQ::CQClient#send_query. The broker forwards the query to a subscriber and returns a QueryResponse containing the response data. Optionally set #cache_key and #cache_ttl for server-side response caching.

Examples:

query = KubeMQ::CQ::QueryMessage.new(
  channel: "queries.user.get",
  timeout: 10_000,
  metadata: "get-user",
  body: '{"user_id": 42}',
  cache_key: "user:42",
  cache_ttl: 60
)
response = client.send_query(query)
puts "Result: #{response.body}, cached: #{response.cache_hit}"

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, timeout:, metadata: nil, body: nil, tags: nil, id: nil, cache_key: nil, cache_ttl: nil) ⇒ QueryMessage

Note:

timeout is in milliseconds

Returns a new instance of QueryMessage.

Parameters:

  • channel (String)

    target channel name (required)

  • timeout (Integer)

    response timeout in milliseconds (required)

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

    arbitrary metadata

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

    message payload

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

    key-value tags (default: {})

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

    message ID (default: auto-generated UUID)

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

    server-side cache key

  • cache_ttl (Integer, nil) (defaults to: nil)

    cache TTL in seconds



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kubemq/cq/query_message.rb', line 57

def initialize(channel:, timeout:, metadata: nil, body: nil, tags: nil, id: nil,
               cache_key: nil, cache_ttl: nil)
  @id = id || SecureRandom.uuid
  @channel = channel
  @timeout = timeout
   = 
  @body = body
  @tags = tags || {}
  @cache_key = cache_key
  @cache_ttl = cache_ttl
end

Instance Attribute Details

#bodyString?

Returns message payload (binary-safe).

Returns:

  • (String, nil)

    message payload (binary-safe)



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#cache_keyString?

Returns cache key for server-side response caching.

Returns:

  • (String, nil)

    cache key for server-side response caching



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#cache_ttlInteger?

Returns cache TTL in seconds.

Returns:

  • (Integer, nil)

    cache TTL in seconds



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#channelString

Returns target channel name.

Returns:

  • (String)

    target channel name



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#idString

Returns unique message identifier (auto-generated UUID if not provided).

Returns:

  • (String)

    unique message identifier (auto-generated UUID if not provided)



46
47
48
# File 'lib/kubemq/cq/query_message.rb', line 46

def id
  @id
end

#metadataString?

Returns arbitrary metadata string.

Returns:

  • (String, nil)

    arbitrary metadata string



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#tagsHash{String => String}

Returns user-defined key-value tags.

Returns:

  • (Hash{String => String})

    user-defined key-value tags



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl

#timeoutInteger

Note:

Timeout is in milliseconds

Returns maximum time to wait for a response.

Returns:

  • (Integer)

    maximum time to wait for a response



46
# File 'lib/kubemq/cq/query_message.rb', line 46

attr_accessor :id, :channel, :metadata, :body, :tags, :timeout, :cache_key, :cache_ttl