Class: KubeMQ::CQ::CommandResponseMessage

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

Overview

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

Construct from the fields of a CommandReceived — copy id to request_id and reply_channel — then set #executed and optionally #error.

Examples:

Respond to a command

response_msg = KubeMQ::CQ::CommandResponseMessage.new(
  request_id: received_cmd.id,
  reply_channel: received_cmd.reply_channel,
  executed: true
)
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, metadata: nil, tags: nil, client_id: nil) ⇒ CommandResponseMessage

Returns a new instance of CommandResponseMessage.

Parameters:

  • request_id (String)

    the original command's request ID (required)

  • reply_channel (String)

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

  • executed (Boolean)

    whether the command was executed (required)

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

    error description on failure

  • 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



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

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

Instance Attribute Details

#client_idString?

Returns responder's client identifier.

Returns:

  • (String, nil)

    responder's client identifier



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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

#errorString?

Returns error description if execution failed.

Returns:

  • (String, nil)

    error description if execution failed



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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

#executedBoolean

Returns whether the command was executed successfully.

Returns:

  • (Boolean)

    whether the command was executed successfully



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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

#metadataString?

Returns response metadata.

Returns:

  • (String, nil)

    response metadata



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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

#reply_channelString

Returns the channel to send the response on.

Returns:

  • (String)

    the channel to send the response on



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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

#request_idString

Returns the original command's request identifier.

Returns:

  • (String)

    the original command's request identifier



36
37
38
# File 'lib/kubemq/cq/command_response_message.rb', line 36

def request_id
  @request_id
end

#tagsHash{String => String}

Returns user-defined key-value tags.

Returns:

  • (Hash{String => String})

    user-defined key-value tags



36
37
# File 'lib/kubemq/cq/command_response_message.rb', line 36

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