Class: Prosody::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/prosody/native_stubs.rb

Overview

Main client for interacting with the Prosody messaging system. Provides methods for sending messages and subscribing to Kafka topics.

See Also:

  • for implementation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(config) ⇒ Client

Creates a new Prosody client with the given configuration.

Examples:

Creating a client with a Configuration object

config = Prosody::Configuration.new do |c|
  c.bootstrap_servers = "localhost:9092"
  c.group_id = "my-consumer-group"
end
client = Prosody::Client.new(config)

Creating a client with a hash

client = Prosody::Client.new(
  bootstrap_servers: "localhost:9092",
  group_id: "my-consumer-group"
)

Parameters:

Returns:

  • (Client)

    A new client instance

Raises:

  • (ArgumentError)

    If the configuration is invalid

  • (RuntimeError)

    If client initialization fails



294
295
296
# File 'lib/prosody/native_stubs.rb', line 294

def self.new(config)
  raise NotImplementedError, "This method is implemented natively in Rust"
end

Instance Method Details

#assigned_partitionsInteger

Returns the number of Kafka partitions currently assigned to this consumer.

This method can be used to monitor the consumer’s workload and ensure proper load balancing across multiple consumer instances.

Returns:

  • (Integer)

    The number of assigned partitions

Raises:

  • (NotImplementedError)


316
317
318
# File 'lib/prosody/native_stubs.rb', line 316

def assigned_partitions
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#consumer_stateSymbol

Returns the current state of the consumer.

The consumer can be in one of three states:

  • ‘:unconfigured` - The consumer has not been configured yet

  • ‘:configured` - The consumer is configured but not running

  • ‘:running` - The consumer is actively consuming messages

Returns:

  • (Symbol)

    The current consumer state

Raises:

  • (NotImplementedError)


306
307
308
# File 'lib/prosody/native_stubs.rb', line 306

def consumer_state
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#is_stalled?Boolean

Checks if the consumer is stalled.

A stalled consumer is one that has stopped processing messages due to errors or reaching processing limits. This can be used to detect unhealthy consumers that need attention.

Returns:

  • (Boolean)

    true if the consumer is stalled, false otherwise

Raises:

  • (NotImplementedError)


327
328
329
# File 'lib/prosody/native_stubs.rb', line 327

def is_stalled?
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#send_message(topic, key, payload) ⇒ void

This method returns an undefined value.

Sends a message to the specified Kafka topic.

Examples:

Sending a simple message

client.send_message("my-topic", "user-123", { event: "login", timestamp: Time.now })

Parameters:

  • topic (String)

    The destination topic name

  • key (String)

    The message key for partitioning

  • payload (Object)

    The message payload (will be serialized to JSON)

Raises:

  • (RuntimeError)

    If the message cannot be sent



341
342
343
# File 'lib/prosody/native_stubs.rb', line 341

def send_message(topic, key, payload)
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#source_systemString

Returns the configured source system identifier.

The source system is used to identify the originating service or component in produced messages, enabling loop detection.

Examples:

Getting the source system

puts client.source_system  # => "my-service"

Returns:

  • (String)

    The source system identifier

Raises:

  • (NotImplementedError)


387
388
389
# File 'lib/prosody/native_stubs.rb', line 387

def source_system
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#subscribe(handler) ⇒ void

This method returns an undefined value.

Subscribes to Kafka topics using the provided handler. The handler must implement an ‘on_message(context, message)` method.

Examples:

Subscribing with a handler

class MyHandler < Prosody::EventHandler
  def on_message(context, message)
    puts "Received message: #{message.payload}"
  end
end

client.subscribe(MyHandler.new)

Parameters:

  • handler (EventHandler)

    A handler object that processes messages

Raises:

  • (RuntimeError)

    If subscription fails



360
361
362
# File 'lib/prosody/native_stubs.rb', line 360

def subscribe(handler)
  raise NotImplementedError, "This method is implemented natively in Rust"
end

#unsubscribevoid

This method returns an undefined value.

Unsubscribes from all topics, stopping message processing.

This method gracefully shuts down the consumer, completing any in-flight messages before stopping.

Examples:

Shutting down a consumer

client.unsubscribe

Raises:

  • (RuntimeError)

    If unsubscription fails



374
375
376
# File 'lib/prosody/native_stubs.rb', line 374

def unsubscribe
  raise NotImplementedError, "This method is implemented natively in Rust"
end