Class: KubeMQ::CQ::CommandMessage

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

Overview

Outbound command message for the request/reply (fire-and-confirm) pattern.

Construct a CommandMessage and pass it to KubeMQ::CQClient#send_command. The broker forwards the command to a subscriber and returns a CommandResponse indicating whether it was executed.

Examples:

cmd = KubeMQ::CQ::CommandMessage.new(
  channel: "commands.user.create",
  timeout: 5000,
  metadata: "create-user",
  body: '{"name": "Alice"}',
  tags: { "source" => "api" }
)
response = client.send_command(cmd)
puts "Executed: #{response.executed}"

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, timeout:, metadata: nil, body: nil, tags: nil, id: nil) ⇒ CommandMessage

Note:

timeout is in milliseconds

Returns a new instance of CommandMessage.

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)



49
50
51
52
53
54
55
56
# File 'lib/kubemq/cq/command_message.rb', line 49

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

Instance Attribute Details

#bodyString?

Returns message payload (binary-safe).

Returns:

  • (String, nil)

    message payload (binary-safe)



40
# File 'lib/kubemq/cq/command_message.rb', line 40

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

#channelString

Returns target channel name.

Returns:

  • (String)

    target channel name



40
# File 'lib/kubemq/cq/command_message.rb', line 40

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

#idString

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

Returns:

  • (String)

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



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

def id
  @id
end

#metadataString?

Returns arbitrary metadata string.

Returns:

  • (String, nil)

    arbitrary metadata string



40
# File 'lib/kubemq/cq/command_message.rb', line 40

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

#tagsHash{String => String}

Returns user-defined key-value tags.

Returns:

  • (Hash{String => String})

    user-defined key-value tags



40
# File 'lib/kubemq/cq/command_message.rb', line 40

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

#timeoutInteger

Note:

Timeout is in milliseconds

Returns maximum time to wait for a response.

Returns:

  • (Integer)

    maximum time to wait for a response



40
# File 'lib/kubemq/cq/command_message.rb', line 40

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