Реализация device-control-service: gRPC + MQTT + Device Shadow в Redis

Добавлен gRPC-контракт proto/device_control (TurnOn/TurnOff/SetLevel),
общий Go-модуль proto/ для переиспользования сгенерированного кода.
device-control-service принимает команды по gRPC, обновляет desired_state
в Redis и публикует их в MQTT; слушает devices/+/telemetry и devices/+/ack
для отметки живости устройства и обновления reported_state; горутина
health-check переводит устройство в offline по таймауту и публикует
событие в RabbitMQ (device.status_changed) для будущего notification-service.

Проверено сквозным тестом через docker compose: grpcurl TurnOn/SetLevel
меняет desired_state и уходит в MQTT, mosquitto_pub с ack обновляет
reported_state и статус, health-check автоматически переводит устройство
в offline по истечении таймаута.
This commit is contained in:
2026-07-26 18:40:36 +05:00
parent 28ca67f42c
commit 3eb84aae6c
23 changed files with 1885 additions and 9 deletions
+36
View File
@@ -0,0 +1,36 @@
syntax = "proto3";
package device_control;
option go_package = "git.cactoz.su/cacto/home_automatization/proto/device_control";
// DeviceControl is the synchronous entry point for issuing commands to a
// device. It covers the generic actuator capabilities used across the
// platform (device_types.capabilities: turn_on, turn_off, set_level) — no
// zone- or device-type-specific methods. A call here updates the device's
// desired state and dispatches the command over MQTT; it does not wait for
// the device to confirm execution (see the Device Shadow pattern in
// device-control-service's README).
service DeviceControl {
rpc TurnOn(TurnOnRequest) returns (CommandResult);
rpc TurnOff(TurnOffRequest) returns (CommandResult);
rpc SetLevel(SetLevelRequest) returns (CommandResult);
}
message TurnOnRequest {
string device_id = 1;
}
message TurnOffRequest {
string device_id = 1;
}
message SetLevelRequest {
string device_id = 1;
double level = 2;
}
message CommandResult {
bool success = 1;
string error = 2;
}