A distributed example implementation of Collektive, demonstrating aggregate programming in a network of distributed devices using MQTT for communication.
This project showcases how to build distributed aggregate computing applications using the Collektive framework. It implements a simple neighboring network where devices communicate via MQTT to exchange information about their neighbors, demonstrating the fundamental concepts of aggregate programming in a distributed environment.
- Multiplatform Support: Runs on both JVM and JavaScript (Node.js) platforms using Kotlin Multiplatform
- MQTT Communication: Devices communicate using the MQTT protocol via a public broker
- Aggregate Programming: Implements the
neighboringoperation to collect information from connected devices - Configurable Network: Customize the number of devices, round time, and execution duration
- JDK: Version 8 or higher
- Gradle: Wrapper included (no installation required)
- Node.js: Version 22.19 (for JavaScript target)
Clone the repository:
git clone https://github.com/Collektive/collektive-example-distributed.git
cd collektive-example-distributedRun the distributed example on the JVM platform:
./gradlew :distributed:jvmRunThis will start 3 devices (IDs 0-2) that communicate via MQTT, each running aggregate cycles every second for 60 seconds.
Run the distributed example on Node.js:
./gradlew :distributed:jsNodeDevelopmentRunThis will start 2 devices (IDs 2-3) using the JavaScript implementation.
The main entrypoint accepts several parameters:
deviceCount: Number of devices in the network (default: 50)startDeviceId: Starting device ID (default: 0)roundTime: Time between aggregate cycles (default: 1 second)executeFor: Total execution duration (default: 60 seconds)asyncNetwork: Whether to use asynchronous network mode (default: false)
Modify the parameters in distributed/src/jvmMain/kotlin/it/unibo/collektive/Main.kt or distributed/src/jsMain/kotlin/it/unibo/collektive/Main.kt to customize behavior.
Build the entire project:
./gradlew buildThis will compile both JVM and JavaScript targets and run code quality checks (ktlint, detekt).
Execute all tests:
./gradlew testRun linting and static analysis:
./gradlew ktlintCheck detektAllAuto-fix linting issues:
./gradlew ktlintFormatcollektive-example-distributed/
├── distributed/ # Main module
│ └── src/
│ ├── commonMain/ # Shared Kotlin code
│ │ └── kotlin/
│ │ └── it/unibo/collektive/
│ │ ├── CommonEntrypoint.kt # Main aggregate program logic
│ │ └── network/ # MQTT mailbox implementation
│ ├── jvmMain/ # JVM-specific code
│ │ └── kotlin/
│ │ └── it/unibo/collektive/
│ │ └── Main.kt # JVM entry point
│ └── jsMain/ # JavaScript-specific code
│ └── kotlin/
│ └── it/unibo/collektive/
│ └── Main.kt # JavaScript entry point
├── buildSrc/ # Build configuration
├── gradle/ # Gradle wrapper and version catalog
├── release.config.js # Semantic release configuration
└── README.md # This file
- Collektive: Aggregate programming DSL (v26.1.2)
- Kotlin: Multiplatform programming language (v2.2.20)
- MQTT: Message protocol for distributed communication
- Kotlinx Serialization: Data serialization (JSON and Protobuf)
- Kotlinx Coroutines: Asynchronous programming
- Kotlin Logging: Structured logging
- Device Initialization: Each device creates an MQTT mailbox connected to a public broker (
test.mosquitto.org) - Aggregate Program: Devices run an aggregate program that collects neighbor information using the
neighboringoperation - Communication: Devices exchange messages via MQTT, broadcasting their state and receiving updates from neighbors
- Cycles: Each device periodically executes aggregate cycles, processing received messages and updating its local state
- Output: Devices log their current neighbor list after each cycle
The project uses pre-commit hooks to ensure code quality:
- Commit message validation: Enforces conventional commits
- Code checks: Runs
detektAllandktlintCheckbefore commits
Hooks are automatically installed when building the project.
The project uses GitHub Actions for CI/CD:
- Builds and tests on multiple platforms (Ubuntu, macOS, Windows)
- Runs code quality checks
- Automated dependency updates via Renovate
- Automated releases using semantic-release
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes using conventional commits
- Ensure all tests pass and code quality checks succeed
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is part of the Collektive ecosystem. Please refer to the main Collektive repository for license information.
- Collektive: The main Collektive DSL and runtime
- Collektive Stdlib: Standard library for aggregate programming
For questions, issues, or contributions, please visit: