Skip to content

Commit e01a32d

Browse files
committed
chore: separated kafka wrapper api into library, made a test app and exposed the wrapper to the godot library.
1 parent 73f7db2 commit e01a32d

15 files changed

+1299
-686
lines changed

CMakeLists.txt

+32-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ project(
55
LANGUAGES CXX
66
)
77

8+
option(BUILD_TESTS "Build the tests" ON)
9+
810
# Generate the project files
911
# execute_process(
1012
# COMMAND scons
@@ -30,8 +32,12 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/demo/server/addons
3032
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
3133

3234
# Glob all sources files.
33-
file(GLOB_RECURSE SOURCES "src/*.cpp")
34-
file(GLOB_RECURSE HEADERS "src/*.hpp" "src/*.h")
35+
file(GLOB_RECURSE GODOT_SOURCES "src/godotkafka/*.cpp")
36+
file(GLOB_RECURSE GODOT_HEADERS "src/godotkafka/*.hpp" "src/godotkafka/*.h")
37+
file(GLOB_RECURSE TEST_SOURCES "src/test/*.cpp")
38+
file(GLOB_RECURSE TEST_HEADERS "src/test/*.hpp" "src/test/*.h")
39+
file(GLOB_RECURSE LIB_SOURCES "src/kafkalib/*.cpp")
40+
file(GLOB_RECURSE LIB_HEADERS "src/kafkalib/*.hpp" "src/kafkalib/*.h" "include/kafkalib/*.hpp" "include/kafkalib/*.h")
3541

3642
# Include OpenSSL
3743
set(OPENSSL_USE_STATIC_LIBS TRUE)
@@ -59,21 +65,41 @@ if (SSL_LIB)
5965
link_libraries(${SSL_LIB})
6066
endif()
6167

68+
add_library(KafkaLib STATIC
69+
${LIB_SOURCES}
70+
${LIB_HEADERS}
71+
)
72+
target_include_directories(KafkaLib PUBLIC include/kafkalib)
73+
6274
add_library(GodotKafka SHARED
63-
${SOURCES}
64-
${HEADERS}
75+
${GODOT_SOURCES}
76+
${GODOT_HEADERS}
6577
)
6678

6779
# Include Godot::cpp
6880
add_subdirectory(godot-cpp)
6981
target_link_libraries(GodotKafka PRIVATE godot::cpp)
82+
target_link_libraries(GodotKafka PRIVATE KafkaLib)
7083
set_target_properties(godot-cpp PROPERTIES FOLDER "External/Godot")
7184

7285
# Include librdkafka
7386
set(RDKAFKA_BUILD_EXAMPLES OFF)
7487
set(RDKAFKA_BUILD_TESTS OFF)
88+
set(RDKAFKA_BUILD_STATIC ON)
7589
add_subdirectory(extern/librdkafka)
76-
target_link_libraries(GodotKafka PRIVATE rdkafka) # rdkafka is the C library and the core.
77-
target_link_libraries(GodotKafka PRIVATE rdkafka++) # rdkafka++ is a C++ wrapper around librdkafka
90+
target_link_libraries(KafkaLib PUBLIC rdkafka) # rdkafka is the C library and the core.
91+
target_link_libraries(KafkaLib PUBLIC rdkafka++) # rdkafka++ is a C++ wrapper around librdkafka
7892
set_target_properties(rdkafka PROPERTIES FOLDER "External/rdkafka")
7993
set_target_properties(rdkafka++ PROPERTIES FOLDER "External/rdkafka")
94+
95+
if (BUILD_TESTS)
96+
add_executable(TestKafkaLib
97+
${TEST_SOURCES}
98+
${TEST_HEADERS}
99+
)
100+
101+
target_link_libraries(TestKafkaLib PRIVATE KafkaLib)
102+
103+
# Force Visual Studio to set this target as the startup project
104+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT TestKafkaLib)
105+
endif()

compose.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: '3.8'
2+
networks:
3+
redpanda_network:
4+
driver: host
5+
volumes:
6+
redpanda-0: null
7+
services:
8+
9+
redpanda-0:
10+
command:
11+
- redpanda
12+
- start
13+
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
14+
# Address the broker advertises to clients that connect to the Kafka API.
15+
# Use the internal addresses to connect to the Redpanda brokers'
16+
# from inside the same Docker network.
17+
# Use the external addresses to connect to the Redpanda brokers'
18+
# from outside the Docker network.
19+
- --advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092
20+
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
21+
# Address the broker advertises to clients that connect to the HTTP Proxy.
22+
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082
23+
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
24+
# Redpanda brokers use the RPC API to communicate with each other internally.
25+
- --rpc-addr redpanda-0:33145
26+
- --advertise-rpc-addr redpanda-0:33145
27+
# Mode dev-container uses well-known configuration properties for development in containers.
28+
- --mode dev-container
29+
# Tells Seastar (the framework Redpanda uses under the hood) to use 1 core on the system.
30+
- --smp 1
31+
- --default-log-level=info
32+
image: docker.redpanda.com/redpandadata/redpanda:v24.2.4
33+
container_name: redpanda-0
34+
volumes:
35+
- redpanda-0:/var/lib/redpanda/data
36+
networks:
37+
- redpanda_network
38+
ports:
39+
- 18081:18081
40+
- 18082:18082
41+
- 19092:19092
42+
- 19644:9644
43+
console:
44+
container_name: redpanda-console
45+
image: docker.redpanda.com/redpandadata/console:v2.7.1
46+
networks:
47+
- redpanda_network
48+
entrypoint: /bin/sh
49+
command: -c 'echo "$$CONSOLE_CONFIG_FILE" > /tmp/config.yml; /app/console'
50+
environment:
51+
CONFIG_FILEPATH: /tmp/config.yml
52+
CONSOLE_CONFIG_FILE: |
53+
kafka:
54+
brokers: ["redpanda-0:9092"]
55+
schemaRegistry:
56+
enabled: true
57+
urls: ["http://redpanda-0:8081"]
58+
redpanda:
59+
adminApi:
60+
enabled: true
61+
urls: ["http://redpanda-0:9644"]
62+
ports:
63+
- 8080:8080
64+
depends_on:
65+
- redpanda-0
66+
67+
# rust-example:
68+
# build:
69+
# context: ./demo/server/rust-example
70+
# dockerfile: Dockerfile
71+
# ports:
72+
# - 8000:8000

demo/client/scripts/network_manager.gd

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ extends Node
33

44
# Called when the node enters the scene tree for the first time.
55
func _ready() -> void:
6-
pass # Replace with function body.
6+
init_network("localhost:9092")
7+
pass
78

89
func init_network(host: String) -> MultiplayerPeer:
910
var socket: MultiplayerPeer;
1011
#if OS.has_feature("dedicated_server"):
1112
print("Connecting to Kafka Broker: ", host)
1213
var kafka: KafkaMultiplayerPeer = KafkaMultiplayerPeer.new();
14+
kafka.register_admin_channel(host, "super")
1315
kafka.register_publisher("server-to-client", host, 1);
1416
kafka.register_subscriber(["client-to-server"], host, "group-name", 1);
1517
socket = kafka;

0 commit comments

Comments
 (0)