新增 token自动提交
This commit is contained in:
@@ -22,6 +22,9 @@ abstract class DataBase {
|
||||
|
||||
// 执行删除操作
|
||||
Future<void> delete(String table, dynamic condition);
|
||||
|
||||
//查询数量
|
||||
Future<int> count(String tbale, {dynamic condition});
|
||||
}
|
||||
|
||||
class DataBaseConfig {
|
||||
|
||||
@@ -50,4 +50,9 @@ class MongoDb implements DataBase {
|
||||
await getCollection(table)
|
||||
.update(condition, data, multiUpdate: multiUpdate);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> count(String tbale, {dynamic condition}) async {
|
||||
return await getCollection(tbale).count(condition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ class NacosDiscovery implements Discovery {
|
||||
'namespaceId': config.namespaceId,
|
||||
});
|
||||
print(rr);
|
||||
//判断心跳是否发送成功
|
||||
if(rr.data["code"]==20404){
|
||||
//实例未注册 重新注册实例
|
||||
healthCheck = false;
|
||||
registerInstance(serviceName, ip, port,groupName: groupName);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class TraceDio {
|
||||
final Uuid uuid = Uuid();
|
||||
|
||||
static late TraceDio _traceDio;
|
||||
String? token;
|
||||
|
||||
TraceDio(Logger logger)
|
||||
: _dio = Dio(),
|
||||
@@ -48,6 +49,9 @@ class TraceDio {
|
||||
tag: "DIO",
|
||||
traceId: traceId,
|
||||
spanId: spanId);
|
||||
if (response.headers["token"] != null) {
|
||||
token = response.headers["token"]?[0];
|
||||
}
|
||||
return handler.next(response); // 继续处理响应
|
||||
},
|
||||
onError: (DioException e, handler) {
|
||||
@@ -71,21 +75,29 @@ class TraceDio {
|
||||
|
||||
Map<String, dynamic>? getHeader(
|
||||
{Map<String, dynamic>? headers, sf.Request? request}) {
|
||||
headers ??= {};
|
||||
if (request != null) {
|
||||
return {
|
||||
...headers,
|
||||
"X-Trace-ID": request.context['request_trace_id'] as String,
|
||||
"X-Span-ID": request.context['request_span_id'] as String
|
||||
};
|
||||
}
|
||||
return null;
|
||||
if (token != null) {
|
||||
headers["token"] = token;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
// 发起 GET 请求
|
||||
Future<Response> get(String url,
|
||||
{Map<String, dynamic>? queryParameters, sf.Request? request}) async {
|
||||
{Map<String, dynamic>? queryParameters,
|
||||
sf.Request? request,
|
||||
ResponseType? responseType}) async {
|
||||
return await _dio.get(url,
|
||||
queryParameters: queryParameters,
|
||||
options: Options(headers: getHeader(request: request)));
|
||||
options: Options(
|
||||
headers: getHeader(request: request), responseType: responseType));
|
||||
}
|
||||
|
||||
// 发起 POST 请求
|
||||
|
||||
@@ -33,6 +33,11 @@ class WebSocket {
|
||||
final channel = WebSocketChannel.connect(wsUrl);
|
||||
try {
|
||||
await channel.ready;
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
if (_config.onOpen != null) {
|
||||
_config.onOpen!();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
print(e);
|
||||
//连接失败
|
||||
@@ -73,6 +78,8 @@ class WebSocketConfig {
|
||||
String host;
|
||||
bool reConnect;
|
||||
void Function(String) messgae;
|
||||
void Function()? onOpen;
|
||||
|
||||
WebSocketConfig(this.host, this.messgae, {this.reConnect = true});
|
||||
WebSocketConfig(this.host, this.messgae,
|
||||
{this.reConnect = true, this.onOpen});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user