97 lines
No EOL
2.6 KiB
Markdown
97 lines
No EOL
2.6 KiB
Markdown
# WebSocket Connection Improvements for InsigniaRequestProcessService
|
|
|
|
## ???????????????????
|
|
|
|
### 1. **????????? Configuration**
|
|
- ????? `WebSocketConfiguration` class ?????????????????????
|
|
- ?????????????????????? ???? appsettings.json
|
|
- ?? default values ???????????????????????
|
|
|
|
### 2. **??????????????????????? WebSocket**
|
|
- ??? `ImmutableList.Create()` ?????? Transports
|
|
- ????? event handlers ????????????????????????
|
|
- ?????? reconnection ?????????
|
|
- Thread-safe ???? lock mechanism
|
|
|
|
### 3. **??????????????? Logging**
|
|
- ??? `ILogger<T>` ??? Console.WriteLine
|
|
- ????? emoji ??????????????? log ???????????
|
|
- Log ??????????????????????????
|
|
|
|
### 4. **???????????????????**
|
|
- Proper exception handling ????????
|
|
- Graceful handling ??? cancellation
|
|
- Delay ??????????????????????????????? busy loop
|
|
|
|
### 5. **????????????????? Notification**
|
|
- ???????????????????????????????
|
|
- ????????????????????????????????
|
|
- ??????????? retry ?????????
|
|
|
|
## ?????????
|
|
|
|
### ???????????? appsettings.json
|
|
```json
|
|
{
|
|
"WebSocket": {
|
|
"Url": "https://bma-ehr.frappet.synology.me",
|
|
"Path": "/api/v1/org-socket",
|
|
"DefaultUserId": "4064c2b2-0414-464a-97c6-4a47c325b9a3",
|
|
"ReconnectionDelay": 1000,
|
|
"ReconnectionAttempts": 5,
|
|
"Timeout": 20000,
|
|
"AutoReconnect": true,
|
|
"TaskDelayOnError": 5000
|
|
}
|
|
}
|
|
```
|
|
|
|
### Log Messages ????????
|
|
- ?? = Service started
|
|
- ?? = Task processing
|
|
- ? = Success operations
|
|
- ? = Error/Failure
|
|
- ?? = Reconnection attempts
|
|
- ?? = WebSocket notifications
|
|
- ?? = Service stopping
|
|
|
|
## ???????????????????
|
|
|
|
1. **Reliability**: ???????????? WebSocket ???????????????????
|
|
2. **Observability**: ???????????? log ???????
|
|
3. **Configurability**: ??????????????????????? configuration
|
|
4. **Maintainability**: ???????????????????????? ??????????
|
|
5. **Resilience**: ?????????????????????????
|
|
|
|
## WebSocket Events ?????????
|
|
|
|
- `EVENT_CONNECT`: ???????????????
|
|
- `EVENT_DISCONNECT`: ????????????????
|
|
- `EVENT_ERROR`: ????????????????
|
|
- `EVENT_CONNECT_ERROR`: ????????????????????????
|
|
- `EVENT_RECONNECT`: ???????????????????
|
|
- `EVENT_RECONNECT_ERROR`: ????????????????????????????
|
|
- `EVENT_RECONNECT_FAILED`: ?????????????????????????
|
|
|
|
## Message Format ??????????? WebSocket
|
|
|
|
```javascript
|
|
{
|
|
"success": true/false,
|
|
"message": "Task Finish" ???? "Task Failed",
|
|
"payload": {
|
|
"completedAt": "timestamp",
|
|
"taskType": "insignia_background_processing",
|
|
"duration": 1234.56, // milliseconds
|
|
"status": "success" ???? "failed"
|
|
// ?????????? error ???? error ??? stackTrace ?????
|
|
}
|
|
}
|
|
```
|
|
|
|
???????? user data:
|
|
```javascript
|
|
{
|
|
"userId": "4064c2b2-0414-464a-97c6-4a47c325b9a3"
|
|
}
|
|
``` |