Class: KubeMQ::BaseClient
- Inherits:
-
Object
- Object
- KubeMQ::BaseClient
- Defined in:
- lib/kubemq/base_client.rb
Overview
This class is thread-safe. The underlying transport and state are protected by a mutex.
Base class for all KubeMQ client types.
Provides shared connection management, channel CRUD operations, and lifecycle methods. Not intended for direct instantiation — use PubSubClient, QueuesClient, or CQClient instead.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
The client's resolved configuration.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
-
#close ⇒ void
Closes the client and releases all resources.
-
#closed? ⇒ Boolean
Returns whether the client has been closed.
-
#create_channel(channel_name:, channel_type:) ⇒ Boolean
Creates a channel on the KubeMQ broker.
-
#delete_channel(channel_name:, channel_type:) ⇒ Boolean
Deletes a channel from the KubeMQ broker.
-
#initialize(address: nil, client_id: nil, auth_token: nil, config: nil, transport: nil, **options) ⇒ BaseClient
constructor
Creates a new client connected to a KubeMQ broker.
-
#list_channels(channel_type:, search: nil) ⇒ Array<ChannelInfo>
Lists channels of the specified type, with optional name filtering.
-
#ping ⇒ ServerInfo
Pings the KubeMQ broker and returns server information.
-
#purge_queue_channel(channel_name:) ⇒ Hash
Purges all messages from a queue channel.
Constructor Details
#initialize(address: nil, client_id: nil, auth_token: nil, config: nil, transport: nil, **options) ⇒ BaseClient
Creates a new client connected to a KubeMQ broker.
Connection is established lazily on first use, not during initialization. Pass individual options or a pre-built Configuration object.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kubemq/base_client.rb', line 44 def initialize(address: nil, client_id: nil, auth_token: nil, config: nil, transport: nil, **) @config = config || Configuration.new( address: address, client_id: client_id, auth_token: auth_token, ** ) @config.validate! @transport = transport || Transport::GrpcTransport.new(@config) @closed = false @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns the client's resolved configuration.
23 24 25 |
# File 'lib/kubemq/base_client.rb', line 23 def config @config end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
23 |
# File 'lib/kubemq/base_client.rb', line 23 attr_reader :config, :transport |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Closes the client and releases all resources.
Cancels active subscriptions, flushes the message buffer, and closes the gRPC channel. This method is idempotent — calling it multiple times is safe.
79 80 81 82 |
# File 'lib/kubemq/base_client.rb', line 79 def close @mutex.synchronize { @closed = true } @transport.close end |
#closed? ⇒ Boolean
Returns whether the client has been closed.
87 88 89 |
# File 'lib/kubemq/base_client.rb', line 87 def closed? @mutex.synchronize { @closed } || @transport.closed? end |
#create_channel(channel_name:, channel_type:) ⇒ Boolean
Creates a channel on the KubeMQ broker.
105 106 107 108 109 110 111 |
# File 'lib/kubemq/base_client.rb', line 105 def create_channel(channel_name:, channel_type:) ensure_not_closed! @transport.ensure_connected! Transport::ChannelManager.create_channel( @transport, @config.client_id, channel_name, channel_type ) end |
#delete_channel(channel_name:, channel_type:) ⇒ Boolean
Deletes a channel from the KubeMQ broker.
123 124 125 126 127 128 129 |
# File 'lib/kubemq/base_client.rb', line 123 def delete_channel(channel_name:, channel_type:) ensure_not_closed! @transport.ensure_connected! Transport::ChannelManager.delete_channel( @transport, @config.client_id, channel_name, channel_type ) end |
#list_channels(channel_type:, search: nil) ⇒ Array<ChannelInfo>
Lists channels of the specified type, with optional name filtering.
145 146 147 148 149 150 151 |
# File 'lib/kubemq/base_client.rb', line 145 def list_channels(channel_type:, search: nil) ensure_not_closed! @transport.ensure_connected! Transport::ChannelManager.list_channels( @transport, @config.client_id, channel_type, search ) end |
#ping ⇒ ServerInfo
Pings the KubeMQ broker and returns server information.
67 68 69 70 71 |
# File 'lib/kubemq/base_client.rb', line 67 def ping ensure_not_closed! @transport.ensure_connected! @transport.ping end |
#purge_queue_channel(channel_name:) ⇒ Hash
Purges all messages from a queue channel.
161 162 163 164 165 166 167 |
# File 'lib/kubemq/base_client.rb', line 161 def purge_queue_channel(channel_name:) ensure_not_closed! @transport.ensure_connected! Transport::ChannelManager.purge_queue( @transport, @config.client_id, channel_name ) end |