How rsocket/rsocket-go works
Main Components
• Core RSocket Engine – Represented by the “core” directory. This is where the heart of the protocol logic lives, including:
• Framing (message encoding/decoding): See core/framing and associated writeable_* files.
• Transport layer: Found in core/transport which handles TCP and Websocket connections.
• Header, error management, and versioning: Managed directly in core.
• Traffic counting and any low-level networking utilities.
• Reactive Streams Abstraction – Represented by the “rx” package which has sub-folders such as mono and flux. These modules implement the reactive streams paradigms (e.g., back-pressure) and are crucial for exposing a “reactive” API.
• Extensions – In the “extension” directory. These contain additional functionalities like authentication and routing as well as metadata composition.
• Load Balancer – Under the “balancer” directory. This component demonstrates strategies (like round robin) to distribute the load and manage groupings.
• CLI Application – In “cmd/rsocket-cli”. This is the front-end interface for users wanting to run RSocket commands (e.g., request/response mode) and get immediate feedback.
• Supporting Components – These include:
• “logger”: Provides logging facilities.
• “payload”: Handles payload construction, supporting varied formats.
• “internal”: Contains various utilities, buffers, session management, fragmentation logic (like splitting/joining of frames), and ancillary routines.
• “lease”: For lease management and flow control.
Relationships and Data Flows
• The CLI components interact with the RSocket core by invoking API calls (via client.go and cmd/rsocket-cli) which, in turn, use the core modules.
• The “core” module coordinates low-level communication by interfacing with the transport layer (found in core/transport) and handles message framing (via core/framing).
• Reactive stream abstractions (in “rx”) are integrated with these components to implement asynchronous, back-pressured communication.
• Extension modules hook into the core engine to enrich its capabilities (e.g., adding authentication or routing metadata).
• Internal utilities support sessions, buffers, and fragmentation – critical to ensuring data integrity and performance.
• The balancer module sits as a utility to help distribute requests if multiple endpoints or groups are involved.
Architectural Patterns and Design Principles
• Layered Architecture: Clear separation between protocol framing, transport (I/O), reactive abstraction, and extensions.
• Modularity & Extensibility: Each component (e.g., balancer, extensions, logger) is encapsulated in its own directory, supporting independent development and testing.
• Reactive and Asynchronous Communication: The design uses reactive streams (mono and flux) to handle asynchronous data flows.
• Test-Driven Development: A vast number of tests suggest a design that emphasizes testability and modular interactions (look for *_test.go across many directories).