增加协议网关模块

V0.5.x
xiwa 2022-03-09 18:45:37 +08:00
parent 1e47b47d77
commit bd06dae340
12 changed files with 280 additions and 1 deletions

View File

@ -11,6 +11,7 @@
<module>manager</module> <module>manager</module>
<module>dao</module> <module>dao</module>
<module>tppa-server</module> <module>tppa-server</module>
<module>protocol</module>
</modules> </modules>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

43
protocol/pom.xml Normal file
View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>protocol</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,17 @@
package cc.iotkit.protocol;
import lombok.Data;
/**
*
*/
@Data
public class DeregisterInfo {
private String productKey;
private String deviceName;
private boolean cascade;
}

View File

@ -0,0 +1,46 @@
package cc.iotkit.protocol;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
*
*/
public interface DeviceBehaviour {
/**
*
*/
@PostMapping("/register")
Result register(@RequestBody RegisterInfo info);
/**
*
*/
@PostMapping("/deregister")
Result deregister(@RequestBody DeregisterInfo info);
/**
* 线
*/
@PostMapping("/online")
void online(String productKey, String deviceName);
/**
* 线
*/
@PostMapping("/offline")
void offline(String productKey, String deviceName);
/**
*
*/
void messageReport(DeviceMessage msg);
/**
* OTA
*/
void otaProgressReport(OtaMessage msg);
}

View File

@ -0,0 +1,24 @@
package cc.iotkit.protocol;
import lombok.Data;
/**
*
*/
@Data
public class DeviceMessage {
public static final String TYPE_REQUEST = "request";
public static final String TYPE_ACK = "ack";
private String productKey;
private String deviceName;
private String type;
private String mid;
private String content;
}

View File

@ -0,0 +1,30 @@
package cc.iotkit.protocol;
import lombok.Data;
/**
* OTA
*/
@Data
public class OtaMessage {
private final String TYPE_PROGRESS="progress";
private final String TYPE_RESULT="result";
private final String PROGRESS_DOWNLOADING="downloading";
private final String PROGRESS_DOWNLOADED="downloaded";
private final String PROGRESS_UPGRADING="upgrading";
private final String PROGRESS_UPGRADED="upgraded";
private String productKey;
private String deviceName;
private String type;
private String jobId;
private String progress;
private String result;
}

View File

@ -0,0 +1,18 @@
package cc.iotkit.protocol;
import lombok.Data;
import java.util.Map;
/**
*
*/
@Data
public class RegisterInfo {
private String productKey;
private String deviceName;
private Map<String,Object> label;
}

View File

@ -0,0 +1,9 @@
package cc.iotkit.protocol;
import lombok.Data;
@Data
public class Result {
}

View File

@ -0,0 +1,24 @@
package cc.iotkit.protocol.config;
import cc.iotkit.protocol.DeviceBehaviour;
import cc.iotkit.protocol.impl.DeviceBehaviourImpl;
import feign.Client;
import feign.Contract;
import feign.codec.Decoder;
import feign.codec.Encoder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ProtocolConfiguration {
@Value("${protocol.server}")
private String protocolServer;
@Bean
public DeviceBehaviour getDeviceBehaviour(Decoder decoder, Encoder encoder, Client client, Contract contract) {
return new DeviceBehaviourImpl(protocolServer, decoder, encoder, client, contract);
}
}

View File

@ -0,0 +1,66 @@
package cc.iotkit.protocol.impl;
import cc.iotkit.protocol.*;
import feign.Client;
import feign.Contract;
import feign.Feign;
import feign.codec.Decoder;
import feign.codec.Encoder;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Import;
@Import(FeignClientsConfiguration.class)
public class DeviceBehaviourImpl implements DeviceBehaviour {
private final Feign.Builder builder;
private final String protocolServer;
private DeviceBehaviour target;
public DeviceBehaviourImpl(String protocolServer, Decoder decoder,
Encoder encoder, Client client, Contract contract) {
this.protocolServer = protocolServer;
this.builder = Feign.builder()
.client(client)
.encoder(encoder)
.decoder(decoder)
.contract(contract);
}
private DeviceBehaviour behaviour() {
if (target == null) {
target = this.builder.target(DeviceBehaviour.class, protocolServer);
}
return target;
}
@Override
public Result register(RegisterInfo info) {
return behaviour().register(info);
}
@Override
public Result deregister(DeregisterInfo info) {
return behaviour().deregister(info);
}
@Override
public void online(String productKey, String deviceName) {
behaviour().online(productKey, deviceName);
}
@Override
public void offline(String productKey, String deviceName) {
behaviour().offline(productKey, deviceName);
}
@Override
public void messageReport(DeviceMessage msg) {
}
@Override
public void otaProgressReport(OtaMessage msg) {
}
}

View File

@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration= cc.iotkit.protocol.config.ProtocolConfiguration

View File

@ -1 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.danbay.iot.commons.logger.config.LoggerAutoConfiguration org.springframework.boot.autoconfigure.EnableAutoConfiguration=cc.iotkit.ruleengine.config.RuleConfiguration