Skip to content

Commit 92488e7

Browse files
committed
feat: integrate Aeron native bindings
1 parent ee72213 commit 92488e7

31 files changed

+2098
-37
lines changed

.github/workflows/build-cpp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
12+
with:
13+
submodules: recursive
1214
- name: Detect C++ project
1315
id: detect
1416
run: |

.github/workflows/build-go.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
12+
with:
13+
submodules: recursive
1214
- name: Detect Go project
1315
id: detect
1416
run: |
@@ -24,7 +26,12 @@ jobs:
2426
go-version: "1.24.x"
2527
- name: Build
2628
if: steps.detect.outputs.present == 'true'
29+
env:
30+
CGO_ENABLED: "1"
31+
LD_LIBRARY_PATH: ${{ github.workspace }}/native/build
2732
run: |
33+
chmod +x native/build.sh
34+
./native/build.sh
2835
cd go
2936
go test ./... -coverprofile=coverage.out
3037
- name: Upload coverage

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ node/dist/
7070

7171
# Build outputs
7272
cppbuild/
73+
native/build/
7374
java/target/
7475
java/.cache/
7576
dotnet/bin/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/aeron"]
2+
path = third_party/aeron
3+
url = https://github.com/aeron-io/aeron.git

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ corepack enable
4343
pnpm install
4444
pnpm run docs:dev
4545
```
46+
47+
## Aeron 原生库
48+
```bash
49+
./native/build.sh
50+
```
51+
非 Java 语言默认从 `native/build` 加载 `epoch_aeron`,或通过 `EPOCH_AERON_LIBRARY` 指定路径。

cpp/CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
cmake_minimum_required(VERSION 3.20)
2-
project(epoch_cpp VERSION 0.1.0 LANGUAGES CXX)
2+
project(epoch_cpp VERSION 0.1.0 LANGUAGES C CXX)
33

44
add_library(epoch_cpp src/epoch.cpp src/engine.cpp src/actor_id.cpp src/aeron_transport.cpp)
55

66
target_include_directories(epoch_cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
77

88
target_compile_features(epoch_cpp PUBLIC cxx_std_17)
99

10+
find_package(Threads REQUIRED)
11+
set(AERON_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/aeron)
12+
set(AERON_CLIENT_DIR ${AERON_ROOT}/aeron-client/src/main/c)
13+
if (EXISTS ${AERON_CLIENT_DIR}/CMakeLists.txt)
14+
include(CheckIncludeFile)
15+
file(STRINGS ${AERON_ROOT}/version.txt AERON_VERSION_TXT LIMIT_COUNT 1)
16+
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ ${AERON_VERSION_TXT})
17+
set(AERON_VERSION_MAJOR ${CMAKE_MATCH_1})
18+
set(AERON_VERSION_MINOR ${CMAKE_MATCH_2})
19+
set(AERON_VERSION_PATCH ${CMAKE_MATCH_3})
20+
execute_process(
21+
COMMAND git -C ${AERON_ROOT} rev-parse --short HEAD
22+
OUTPUT_VARIABLE AERON_VERSION_GITSHA
23+
OUTPUT_STRIP_TRAILING_WHITESPACE
24+
ERROR_QUIET)
25+
if (AERON_VERSION_GITSHA STREQUAL "")
26+
set(AERON_VERSION_GITSHA "unknown")
27+
endif()
28+
add_definitions(-DAERON_VERSION_TXT="${AERON_VERSION_TXT}")
29+
add_definitions(-DAERON_VERSION_MAJOR=${AERON_VERSION_MAJOR})
30+
add_definitions(-DAERON_VERSION_MINOR=${AERON_VERSION_MINOR})
31+
add_definitions(-DAERON_VERSION_PATCH=${AERON_VERSION_PATCH})
32+
add_definitions(-DAERON_VERSION_GITSHA="${AERON_VERSION_GITSHA}")
33+
set(AERON_INSTALL_TARGETS OFF CACHE BOOL "" FORCE)
34+
add_subdirectory(${AERON_CLIENT_DIR} ${CMAKE_CURRENT_BINARY_DIR}/aeron-client)
35+
target_link_libraries(epoch_cpp PUBLIC aeron::aeron_static)
36+
else()
37+
message(FATAL_ERROR "Aeron submodule not found. Run: git submodule update --init --recursive")
38+
endif()
39+
1040
enable_testing()
1141
add_executable(epoch_cpp_test tests/epoch_vector_test.cpp)
1242
target_link_libraries(epoch_cpp_test PRIVATE epoch_cpp)

cpp/include/epoch/aeron_transport.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include "epoch/transport.h"
44

5+
#include <aeronc.h>
6+
7+
#include <cstdint>
58
#include <string>
69

710
namespace epoch {
@@ -10,19 +13,46 @@ struct AeronConfig {
1013
std::string channel;
1114
std::int32_t stream_id;
1215
std::string aeron_directory;
16+
std::int32_t fragment_limit = 64;
17+
std::int32_t offer_max_attempts = 10;
18+
};
19+
20+
struct AeronStats {
21+
std::int64_t sent_count = 0;
22+
std::int64_t received_count = 0;
23+
std::int64_t offer_back_pressure = 0;
24+
std::int64_t offer_not_connected = 0;
25+
std::int64_t offer_admin_action = 0;
26+
std::int64_t offer_closed = 0;
27+
std::int64_t offer_max_position = 0;
28+
std::int64_t offer_failed = 0;
1329
};
1430

1531
class AeronTransport final : public Transport {
1632
public:
1733
explicit AeronTransport(AeronConfig config);
34+
~AeronTransport() override;
35+
36+
AeronTransport(const AeronTransport &) = delete;
37+
AeronTransport &operator=(const AeronTransport &) = delete;
38+
AeronTransport(AeronTransport &&) = delete;
39+
AeronTransport &operator=(AeronTransport &&) = delete;
1840

1941
void send(const Message &message) override;
2042
std::vector<Message> poll(std::size_t max) override;
2143
void close() override;
2244

45+
const AeronConfig &config() const;
46+
const AeronStats &stats() const;
47+
2348
private:
2449
AeronConfig config_;
50+
AeronStats stats_;
2551
bool closed_ = false;
52+
aeron_context_t *context_ = nullptr;
53+
aeron_t *client_ = nullptr;
54+
aeron_publication_t *publication_ = nullptr;
55+
aeron_subscription_t *subscription_ = nullptr;
2656
};
2757

2858
} // namespace epoch

0 commit comments

Comments
 (0)