1.物消息路由转发功能

2.物解析功能
This commit is contained in:
2023-08-14 21:06:19 +08:00
parent 02f5f7c031
commit 1d75cce63d
34 changed files with 869 additions and 449 deletions

View File

@@ -4,7 +4,12 @@ import static org.junit.Assert.assertTrue;
import com.alibaba.nacos.shaded.com.google.common.reflect.TypeToken;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.graphbuilder.math.func.EFunction;
import com.njcn.access.AccessBootApplication;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.TypeEnum;
import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.pojo.dto.mqtt.MqttClientDto;
import io.lettuce.core.protocol.CompleteableCommand;
import okhttp3.Credentials;
@@ -12,7 +17,12 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -26,6 +36,9 @@ import java.util.stream.Collectors;
/**
* Unit test for simple App.
*/
@RunWith(SpringRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = AccessBootApplication.class)
public class AppTest
{
/**
@@ -37,30 +50,43 @@ public class AppTest
assertTrue( true );
}
@Resource
private MqttPublisher publisher;
public static void main(String[] args) {
try {
String username = "ac760c62395cecec";
String password = "k0vGfe5xOE2Bl4DCF73uahcknvcwoKOEDPnOkMvuSBB";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://192.168.1.18:18083/api/v5/clients/access-boot123456")
.header("Content-Type", "application/json")
.header("Authorization", Credentials.basic(username, password))
.build();
Response response = client.newCall(request).execute();
response.body();
String res = Objects.requireNonNull(response.body()).string();
Gson gson = new Gson();
MqttClientDto mqttClientDto = gson.fromJson(res, new TypeToken<MqttClientDto>(){}.getType());
System.out.println("mqttClientDto==:" + mqttClientDto.isConnected());
} catch (IOException e) {
e.printStackTrace();
}
@Test
public void test() {
ReqAndResDto reqAndResParam = new ReqAndResDto();
reqAndResParam.setMid(1);
reqAndResParam.setDid(0);
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(4866);
publisher.send("/Dev/Data1/V1/123", new Gson().toJson(reqAndResParam),1,false);
}
// public static void main(String[] args) {
// try {
// String username = "ac760c62395cecec";
// String password = "k0vGfe5xOE2Bl4DCF73uahcknvcwoKOEDPnOkMvuSBB";
//
// OkHttpClient client = new OkHttpClient();
//
// Request request = new Request.Builder()
// .url("http://192.168.1.18:18083/api/v5/clients/access-boot123456")
// .header("Content-Type", "application/json")
// .header("Authorization", Credentials.basic(username, password))
// .build();
//
// Response response = client.newCall(request).execute();
// response.body();
// String res = Objects.requireNonNull(response.body()).string();
//
// Gson gson = new Gson();
// MqttClientDto mqttClientDto = gson.fromJson(res, new TypeToken<MqttClientDto>(){}.getType());
// System.out.println("mqttClientDto==:" + mqttClientDto.isConnected());
//
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}