Skip to content

Commit

Permalink
feat: KVS 채널 삭제 시 shadow 업데이트할 수 있는 객체 추가 (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywonchae1 committed Nov 29, 2024
1 parent f5d0375 commit 4bd31e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.ioteatime.meonghanyangserver.clients.iot;

import java.util.HashMap;
import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.common.exception.InternalServerException;
import org.ioteatime.meonghanyangserver.common.type.IoTErrorType;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.crt.mqtt.QualityOfService;
import software.amazon.awssdk.iot.iotshadow.IotShadowClient;
Expand All @@ -13,15 +16,21 @@ public class IotShadowMqttClient {
private final IotShadowClient iotShadowClient;

public void updateShadow(String thingName, String key, boolean value) {
ShadowState shadowState = new ShadowState();
shadowState.desired.put(key, value);
shadowState.reportedIsNullable = true;
try {
ShadowState shadowState = new ShadowState();
shadowState.desired = new HashMap<>();
shadowState.desired.put(key, value);
shadowState.reportedIsNullable = true;

UpdateShadowRequest updateShadowRequest = new UpdateShadowRequest();
updateShadowRequest.state = shadowState;
UpdateShadowRequest updateShadowRequest = new UpdateShadowRequest();
updateShadowRequest.state = shadowState;

updateShadowRequest.thingName = thingName;
updateShadowRequest.thingName = thingName;

iotShadowClient.PublishUpdateShadow(updateShadowRequest, QualityOfService.AT_LEAST_ONCE);
iotShadowClient.PublishUpdateShadow(
updateShadowRequest, QualityOfService.AT_LEAST_ONCE);
} catch (Exception e) {
throw new InternalServerException(IoTErrorType.UPDATE_SHADOW);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ioteatime.meonghanyangserver.common.type;

public enum IoTErrorType implements ErrorTypeCode {
UPDATE_SHADOW("INTERNAL_SERVER", "Shadow 갱신에 실패하였습니다.");

private final String message;
private final String description;

IoTErrorType(String message, String description) {
this.message = message;
this.description = description;
}

@Override
public String getMessage() {
return this.message;
}

@Override
public String getDescription() {
return this.description;
}
}

0 comments on commit 4bd31e0

Please sign in to comment.