Class: KubeMQ::ChannelInfo

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

Overview

Metadata about a KubeMQ channel returned by BaseClient#list_channels.

Examples:

channels = client.list_channels(channel_type: KubeMQ::ChannelType::EVENTS)
channels.each do |ch|
  puts "#{ch.name} active=#{ch.active?} in=#{ch.incoming} out=#{ch.outgoing}"
end

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, last_activity: 0, is_active: false, incoming: 0, outgoing: 0) ⇒ ChannelInfo

Creates a new ChannelInfo instance.

Parameters:

  • name (String)

    channel name

  • type (String)

    channel type (one of KubeMQ::ChannelType constants)

  • last_activity (Integer) (defaults to: 0)

    Unix timestamp of last activity (default: 0)

  • is_active (Boolean) (defaults to: false)

    whether the channel has active subscribers (default: false)

  • incoming (Integer) (defaults to: 0)

    total incoming message count (default: 0)

  • outgoing (Integer) (defaults to: 0)

    total outgoing message count (default: 0)



37
38
39
40
41
42
43
44
# File 'lib/kubemq/channel_info.rb', line 37

def initialize(name:, type:, last_activity: 0, is_active: false, incoming: 0, outgoing: 0)
  @name = name
  @type = type
  @last_activity = last_activity
  @is_active = is_active
  @incoming = incoming
  @outgoing = outgoing
end

Instance Attribute Details

#incomingInteger (readonly)

Returns total number of incoming messages.

Returns:

  • (Integer)

    total number of incoming messages



27
# File 'lib/kubemq/channel_info.rb', line 27

attr_reader :name, :type, :last_activity, :is_active, :incoming, :outgoing

#is_activeBoolean (readonly)

Returns whether the channel currently has active subscribers.

Returns:

  • (Boolean)

    whether the channel currently has active subscribers



27
# File 'lib/kubemq/channel_info.rb', line 27

attr_reader :name, :type, :last_activity, :is_active, :incoming, :outgoing

#last_activityInteger (readonly)

Returns Unix timestamp of the last activity on this channel.

Returns:

  • (Integer)

    Unix timestamp of the last activity on this channel



27
# File 'lib/kubemq/channel_info.rb', line 27

attr_reader :name, :type, :last_activity, :is_active, :incoming, :outgoing

#nameString (readonly)

Returns channel name.

Returns:

  • (String)

    channel name



27
28
29
# File 'lib/kubemq/channel_info.rb', line 27

def name
  @name
end

#outgoingObject (readonly)

Returns the value of attribute outgoing.



27
# File 'lib/kubemq/channel_info.rb', line 27

attr_reader :name, :type, :last_activity, :is_active, :incoming, :outgoing

#typeString (readonly)

Returns channel type (one of KubeMQ::ChannelType constants).

Returns:



27
# File 'lib/kubemq/channel_info.rb', line 27

attr_reader :name, :type, :last_activity, :is_active, :incoming, :outgoing

Class Method Details

.from_json(hash) ⇒ ChannelInfo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Constructs a KubeMQ::ChannelInfo from a parsed JSON hash.

Accepts both camelCase (from the broker REST API) and snake_case keys.

Parameters:

  • hash (Hash)

    parsed JSON hash with channel metadata

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kubemq/channel_info.rb', line 60

def self.from_json(hash)
  is_active_val = if hash.key?('isActive') then hash['isActive']
                  elsif hash.key?('is_active') then hash['is_active']
                  elsif hash.key?(:is_active) then hash[:is_active]
                  else false
                  end

  new(
    name: hash['name'] || hash[:name] || '',
    type: hash['type'] || hash[:type] || '',
    last_activity: hash['lastActivity'] || hash['last_activity'] || hash[:last_activity] || 0,
    is_active: is_active_val,
    incoming: hash['incoming'] || hash[:incoming] || 0,
    outgoing: hash['outgoing'] || hash[:outgoing] || 0
  )
end

Instance Method Details

#active?Boolean

Returns whether the channel currently has active subscribers.

Returns:

  • (Boolean)


49
50
51
# File 'lib/kubemq/channel_info.rb', line 49

def active?
  @is_active
end

#to_sString

Returns a human-readable summary of the channel information.

Returns:

  • (String)


80
81
82
# File 'lib/kubemq/channel_info.rb', line 80

def to_s
  "ChannelInfo(name=#{@name}, type=#{@type}, active=#{active?})"
end