This section provides API reference documentation for value objects used in the RabbitMQ Streams Protocol client.
All value objects are immutable and located in src/VO/ and src/Client/ directories.
Specifies where to start consuming from a stream. Located in src/VO/OffsetSpec.php.
The OffsetSpec value object defines the starting position for a consumer subscription. It supports first/last/next, a specific offset, and a timestamp — the five offset types the RabbitMQ Stream protocol defines (plus none, valid only in a ConsumerUpdate reply).
| Constant | Value | Description |
|---|---|---|
TYPE_NONE |
0x0000 | Keep current position (valid only in a ConsumerUpdate reply) |
TYPE_FIRST |
0x0001 | Start from the first message in the stream |
TYPE_LAST |
0x0002 | Start from the last chunk, delivered in full (not the last message) |
TYPE_NEXT |
0x0003 | Start at the end of the stream — messages written after the subscription (not "after the last consumed") |
TYPE_OFFSET |
0x0004 | Start from a specific offset value (inclusive) |
TYPE_TIMESTAMP |
0x0005 | Start at the first chunk whose chunk timestamp is >= the value, in milliseconds since the epoch (chunk-granular, delivered in full) |
public function __construct(
private readonly int $type,
private readonly ?int $value = null
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$type |
int |
Yes | One of the TYPE_* constants |
$value |
?int |
Depends | Offset value; required (and enforced) for TYPE_OFFSET and TYPE_TIMESTAMP, and rejected (and enforced) for the value-less types TYPE_NONE, TYPE_FIRST, TYPE_LAST and TYPE_NEXT. |
Throws:
InvalidArgumentException- If an invalid type is provided, ifTYPE_OFFSET/TYPE_TIMESTAMPis used without a value, or if a value-less type (TYPE_NONE/TYPE_FIRST/TYPE_LAST/TYPE_NEXT) is given a value
TYPE_TIMESTAMPis encoded as a signedint64(milliseconds since the Unix epoch), so negative (pre-1970) timestamps round-trip correctly.TYPE_OFFSETis encoded as an unsigneduint64.
Create an offset spec for the first message.
public static function first(): selfExample:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
$offset = OffsetSpec::first();Create an offset spec for the last chunk of messages, which the broker delivers in full.
public static function last(): selfExample:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
$offset = OffsetSpec::last();Create an offset spec for the end of the stream; the broker delivers messages published after the subscription.
public static function next(): selfExample:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
$offset = OffsetSpec::next();Create an offset spec for a specific absolute offset in the stream. The offset is inclusive; if retention has removed it, the broker attaches at the first offset still available.
public static function offset(int $offset): selfParameters:
| Parameter | Type | Description |
|---|---|---|
$offset |
int |
Absolute offset to start from (inclusive) |
Example:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
$offset = OffsetSpec::offset(1000); // Start from offset 1000Create an offset spec for a specific timestamp.
public static function timestamp(int $timestamp): selfThe broker resolves the value to the first chunk whose chunk timestamp is
>= the value and delivers that chunk in full (a tie selects the earlier
chunk); an out-of-range value clamps to the closest end of the log. Because
chunks share one timestamp, derive the boundary from broker-written
Message::getTimestamp() values rather than the client clock.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$timestamp |
int |
Unix timestamp in milliseconds since the epoch |
Example:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
$timestamp = (time() - 3600) * 1000; // 1 hour ago, in milliseconds
$offset = OffsetSpec::timestamp($timestamp);public function getType(): intReturns the offset type constant.
public function getValue(): ?intReturns the offset value (if applicable).
ToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to array
Used in:
SubscribeRequestV1-src/Request/SubscribeRequestV1.phpConsumer-src/Client/Consumer.phpConnection::createConsumer()-src/Client/Connection.phpResolveOffsetSpecRequestV1-src/Request/ResolveOffsetSpecRequestV1.php
Example:
use CrazyGoat\RabbitStream\VO\OffsetSpec;
use CrazyGoat\RabbitStream\Client\Connection;
$connection = Connection::create(
host: 'localhost',
port: 5552,
user: 'guest',
password: 'guest',
);
// Subscribe from the beginning
$consumer = $connection->createConsumer(
'my-stream',
OffsetSpec::first()
);
// Subscribe from the most recent chunk
$consumer = $connection->createConsumer(
'my-stream',
OffsetSpec::last()
);
// Subscribe from a specific offset
$consumer = $connection->createConsumer(
'my-stream',
OffsetSpec::offset(5000)
);Simple key-value pair for protocol properties. Located in src/VO/KeyValue.php.
The KeyValue value object represents a string key-value pair used throughout the protocol for properties, metadata, and configuration.
public function __construct(
private readonly string $key,
private readonly ?string $value
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$key |
string |
Yes | The property key |
$value |
?string |
Yes | The property value (can be null) |
public function getKey(): stringReturns the key.
public function getValue(): ?stringReturns the value (may be null).
FromStreamBufferInterface- Can be deserialized from protocol bufferToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
OpenResponseV1- Connection properties -src/Response/OpenResponseV1.phpPeerPropertiesResponseV1- Peer properties -src/Response/PeerPropertiesResponseV1.phpPeerPropertiesRequestV1- Client properties -src/Request/PeerPropertiesRequestV1.phpCreateRequestV1- Stream arguments -src/Request/CreateRequestV1.phpCreateSuperStreamRequestV1- Super stream arguments -src/Request/CreateSuperStreamRequestV1.php
Example:
use CrazyGoat\RabbitStream\VO\KeyValue;
// Create a key-value pair
$property = new KeyValue('product', 'MyApplication');
echo $property->getKey(); // "product"
echo $property->getValue(); // "MyApplication"
// With null value
$property = new KeyValue('empty', null);
echo $property->getValue(); // null
// Convert to array
$array = $property->toArray();
// ['key' => 'empty', 'value' => null]Message to be published (v1 protocol). Located in src/VO/PublishedMessage.php.
The PublishedMessage value object represents a single message to be published to a stream using the v1 protocol format.
public function __construct(
private readonly int $publishingId,
private readonly string $message,
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$publishingId |
int |
Yes | Unique publishing ID for deduplication |
$message |
string |
Yes | Message body as binary string |
public function getPublishingId(): intReturns the publishing ID.
ToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to array
Used in:
PublishRequestV1-src/Request/PublishRequestV1.phpProducer::send()-src/Client/Producer.php
Example:
use CrazyGoat\RabbitStream\VO\PublishedMessage;
// Create a message with publishing ID
$message = new PublishedMessage(
publishingId: 1,
message: 'Hello, World!'
);
// Get the publishing ID
$id = $message->getPublishingId(); // 1
// Convert to array
$array = $message->toArray();
// ['publishingId' => 1, 'data' => 'Hello, World!']Message to be published with filter support (v2 protocol). Located in src/VO/PublishedMessageV2.php.
The PublishedMessageV2 value object extends PublishedMessage with filter value support for the v2 protocol, enabling message filtering on the server side.
public function __construct(
private readonly int $publishingId,
private readonly string $filterValue,
private readonly string $message,
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$publishingId |
int |
Yes | Unique publishing ID for deduplication |
$filterValue |
string |
Yes | Filter value for server-side filtering |
$message |
string |
Yes | Message body as binary string |
public function getPublishingId(): intReturns the publishing ID.
ToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to array
Used in:
PublishRequestV2-src/Request/PublishRequestV2.php
Example:
use CrazyGoat\RabbitStream\VO\PublishedMessageV2;
// Create a filtered message
$message = new PublishedMessageV2(
publishingId: 1,
filterValue: 'order-type:priority',
message: json_encode(['order_id' => 123, 'priority' => 'high'])
);
// Get the publishing ID
$id = $message->getPublishingId(); // 1
// Convert to array
$array = $message->toArray();
// ['publishingId' => 1, 'filterValue' => 'order-type:priority', 'data' => '{...}']Error information for failed publish operations. Located in src/VO/PublishingError.php.
The PublishingError value object contains details about a failed publish operation, including the publishing ID and error code.
public function __construct(
private readonly int $publishingId,
private readonly int $code,
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$publishingId |
int |
Yes | The publishing ID that failed |
$code |
int |
Yes | Error code (see ResponseCodeEnum) |
public function getPublishingId(): intReturns the publishing ID that failed.
public function getCode(): intReturns the error code.
FromStreamBufferInterface- Can be deserialized from protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
PublishErrorResponseV1-src/Response/PublishErrorResponseV1.php
Example:
use CrazyGoat\RabbitStream\VO\PublishingError;
use CrazyGoat\RabbitStream\Enum\ResponseCodeEnum;
// Create from response
$error = new PublishingError(
publishingId: 42,
code: ResponseCodeEnum::STREAM_NOT_EXIST->value
);
// Get error details
$publishingId = $error->getPublishingId(); // 42
$errorCode = $error->getCode(); // 2
// Convert to array
$array = $error->toArray();
// ['publishingId' => 42, 'code' => 2]Represents a RabbitMQ broker node. Located in src/VO/Broker.php.
The Broker value object contains information about a RabbitMQ broker node, including its reference ID, host, and port.
public function __construct(
private readonly int $reference,
private readonly string $host,
private readonly int $port
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$reference |
int |
Yes | Broker reference ID |
$host |
string |
Yes | Broker hostname or IP address |
$port |
int |
Yes | Broker port number |
public function getReference(): intReturns the broker reference ID.
public function getHost(): stringReturns the broker hostname.
public function getPort(): intReturns the broker port.
FromStreamBufferInterface- Can be deserialized from protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
MetadataResponseV1-src/Response/MetadataResponseV1.php
Example:
use CrazyGoat\RabbitStream\VO\Broker;
// Create a broker reference
$broker = new Broker(
reference: 1,
host: 'rabbitmq.example.com',
port: 5552
);
// Get broker details
echo $broker->getReference(); // 1
echo $broker->getHost(); // "rabbitmq.example.com"
echo $broker->getPort(); // 5552
// Convert to array
$array = $broker->toArray();
// ['reference' => 1, 'host' => 'rabbitmq.example.com', 'port' => 5552]Metadata about a stream including leader and replicas. Located in src/VO/StreamMetadata.php.
The StreamMetadata value object contains comprehensive metadata about a stream, including its name, response code, leader broker reference, and replica broker references.
/**
* @param array<int, int> $replicasReferences
*/
public function __construct(
private readonly string $streamName,
private readonly int $responseCode,
private readonly int $leaderReference,
private readonly array $replicasReferences
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$streamName |
string |
Yes | Name of the stream |
$responseCode |
int |
Yes | Response code (0 for success) |
$leaderReference |
int |
Yes | Reference ID of the leader broker |
$replicasReferences |
array<int, int> |
Yes | Array of replica broker reference IDs |
public function getStreamName(): stringReturns the stream name.
public function getResponseCode(): intReturns the response code (0 indicates success).
public function getLeaderReference(): intReturns the leader broker reference ID.
/**
* @return array<int, int>
*/
public function getReplicasReferences(): arrayReturns an array of replica broker reference IDs.
FromStreamBufferInterface- Can be deserialized from protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
MetadataResponseV1-src/Response/MetadataResponseV1.phpConnection::createStream()-src/Client/Connection.php
Example:
use CrazyGoat\RabbitStream\VO\StreamMetadata;
// Create stream metadata
$metadata = new StreamMetadata(
streamName: 'my-stream',
responseCode: 0,
leaderReference: 1,
replicasReferences: [2, 3]
);
// Get metadata
echo $metadata->getStreamName(); // "my-stream"
echo $metadata->getResponseCode(); // 0
echo $metadata->getLeaderReference(); // 1
print_r($metadata->getReplicasReferences()); // [2, 3]
// Convert to array
$array = $metadata->toArray();
// ['stream' => 'my-stream', 'responseCode' => 0, 'leaderReference' => 1, 'replicasReferences' => [2, 3]]Supported protocol command versions. Located in src/VO/CommandVersion.php.
The CommandVersion value object represents the version range supported for a specific protocol command, used during version negotiation.
public function __construct(
private readonly int $key,
private readonly int $minVersion,
private readonly int $maxVersion
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$key |
int |
Yes | Command key (from KeyEnum) |
$minVersion |
int |
Yes | Minimum supported version |
$maxVersion |
int |
Yes | Maximum supported version |
public function getKey(): intReturns the command key.
public function getMinVersion(): intReturns the minimum supported version.
public function getMaxVersion(): intReturns the maximum supported version.
FromStreamBufferInterface- Can be deserialized from protocol bufferToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
ExchangeCommandVersionsRequestV1-src/Request/ExchangeCommandVersionsRequestV1.phpExchangeCommandVersionsResponseV1-src/Response/ExchangeCommandVersionsResponseV1.php
Example:
use CrazyGoat\RabbitStream\VO\CommandVersion;
use CrazyGoat\RabbitStream\Enum\KeyEnum;
// Create a command version
$version = new CommandVersion(
key: KeyEnum::PUBLISH->value,
minVersion: 1,
maxVersion: 2
);
// Get version info
echo $version->getKey(); // 2 (PUBLISH)
echo $version->getMinVersion(); // 1
echo $version->getMaxVersion(); // 2
// Convert to array
$array = $version->toArray();
// ['key' => 2, 'minVersion' => 1, 'maxVersion' => 2]Stream statistics key-value pair. Located in src/VO/Statistic.php.
The Statistic value object represents a single stream statistic as a key-value pair, where the value is an integer (typically a count or size).
public function __construct(
private readonly string $key,
private readonly int $value
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$key |
string |
Yes | Statistic name/key |
$value |
int |
Yes | Statistic value |
public function getKey(): stringReturns the statistic key.
public function getValue(): intReturns the statistic value.
FromStreamBufferInterface- Can be deserialized from protocol bufferToStreamBufferInterface- Can be serialized to protocol bufferToArrayInterface- Can be converted to arrayFromArrayInterface- Can be created from array
Used in:
StreamStatsResponseV1-src/Response/StreamStatsResponseV1.php
Example:
use CrazyGoat\RabbitStream\VO\Statistic;
// Create a statistic
$stat = new Statistic(
key: 'publishers',
value: 5
);
// Get statistic info
echo $stat->getKey(); // "publishers"
echo $stat->getValue(); // 5
// Convert to array
$array = $stat->toArray();
// ['key' => 'publishers', 'value' => 5]Status of a publish confirmation. Located in src/Client/ConfirmationStatus.php.
The ConfirmationStatus value object is passed to the onConfirm callback in the Producer class to indicate whether a message was successfully confirmed by the server.
public function __construct(
private readonly bool $confirmed,
private readonly ?int $errorCode = null,
private readonly ?int $publishingId = null,
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$confirmed |
bool |
Yes | Whether the message was confirmed |
$errorCode |
?int |
No | Error code if confirmation failed |
$publishingId |
?int |
No | Publishing ID of the message |
public function isConfirmed(): boolReturns true if the message was successfully confirmed by the server.
public function getErrorCode(): ?intReturns the error code if the message failed, or null if confirmed successfully.
Common error codes:
0x02-STREAM_NOT_EXIST- Stream does not exist0x12-PUBLISHER_NOT_EXIST- Publisher ID is invalid0x10-ACCESS_REFUSED- No write permission
See ResponseCodeEnum for all error codes.
public function getPublishingId(): ?intReturns the publishing ID of the message, or null if not available.
Used in:
Producerconfirmation callback -src/Client/Producer.php
Example:
use CrazyGoat\RabbitStream\Client\Connection;
use CrazyGoat\RabbitStream\Client\ConfirmationStatus;
$connection = new Connection('localhost', 5552);
$connection->connect();
$producer = $connection->createProducer(
'my-stream',
onConfirm: function (ConfirmationStatus $status) {
if ($status->isConfirmed()) {
echo "Message #{$status->getPublishingId()} confirmed\n";
} else {
$errorCode = $status->getErrorCode();
echo "Message failed with error code: {$errorCode}\n";
}
}
);
$producer->send('Hello, World!');
$producer->waitForConfirms(timeout: 5.0);Single entry within an Osiris chunk. Located in src/Client/ChunkEntry.php.
The ChunkEntry value object represents a single message entry within a chunk delivered by the server. It contains the message offset, data, and timestamp.
public function __construct(
private readonly int $offset,
private readonly string $data,
private readonly int $timestamp,
)Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
$offset |
int |
Yes | Message offset in the stream |
$data |
string |
Yes | Message data as binary string |
$timestamp |
int |
Yes | Chunk timestamp shared by every entry of the chunk (milliseconds since the Unix epoch) |
public function getOffset(): intReturns the message offset in the stream.
public function getData(): stringReturns the message data as a binary string.
public function getTimestamp(): intReturns the chunk timestamp (milliseconds since the Unix epoch) shared by every entry of the chunk.
Used in:
OsirisChunkParser::parse()-src/Client/OsirisChunkParser.phpAmqpMessageDecoder::decode()-src/Client/AmqpMessageDecoder.php
Example:
use CrazyGoat\RabbitStream\Client\ChunkEntry;
// Create a chunk entry (typically created by parser)
$entry = new ChunkEntry(
offset: 1000,
data: 'Hello, World!',
timestamp: (int) (microtime(true) * 1000)
);
// Get entry info
echo $entry->getOffset(); // 1000
echo $entry->getData(); // "Hello, World!"
echo $entry->getTimestamp(); // 1234567890123
// Decode AMQP message
use CrazyGoat\RabbitStream\Client\AmqpMessageDecoder;
$message = AmqpMessageDecoder::decode($entry->getData());PublishedMessage- Single message for v1 protocolPublishedMessageV2- Message with filter support for v2 protocolPublishingError- Error details for failed publishesConfirmationStatus- Confirmation status for published messages
OffsetSpec- Starting position specification for consumersChunkEntry- Individual message within a delivered chunk
StreamMetadata- Stream metadata including leader and replicasStatistic- Stream statistics key-value pair
Broker- RabbitMQ broker node informationKeyValue- Generic key-value pair for propertiesCommandVersion- Protocol command version information
Most value objects implement one or more of these interfaces:
FromStreamBufferInterface- Deserialization from protocol bufferToStreamBufferInterface- Serialization to protocol bufferToArrayInterface- Conversion to arrayFromArrayInterface- Creation from array
- Producer API Reference - Uses PublishedMessage, ConfirmationStatus
- Consumer API Reference - Uses OffsetSpec, ChunkEntry
- Enums Reference - ResponseCodeEnum for error codes
- Source:
src/VO/andsrc/Client/directories