# web通信应用 **Repository Path**: hongfff/Middleware_Lab_3 ## Basic Information - **Project Name**: web通信应用 - **Description**: 使用ActiveMQ构建的spring服务器,提供一对一的消息通信服务,可调用翻译api与LLM api进行实时的文本翻译和消息分析回复建议功能 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-10 - **Last Updated**: 2026-04-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MiddlewareLab3 Real-time Chat Server A real-time chat application based on Spring Boot + WebSocket, supporting message translation, sentiment analysis, and user preference management. ## Project Overview MiddlewareLab3 is a middleware laboratory project providing real-time chat functionality, integrated with Tencent Cloud Machine Translation and Alibaba Cloud Sentiment Analysis services. It implements real-time communication via WebSocket and manages message queues using ActiveMQ. ## Technology Stack - **Backend Framework**: Spring Boot 2.x - **WebSocket**: Spring WebSocket - **Message Queue**: ActiveMQ - **Translation Service**: Tencent Cloud Machine Translation - **Sentiment Analysis**: Alibaba Cloud DashScope (Qwen) - **Build Tool**: Maven ## Features - Real-time WebSocket chat - Automatic message translation (multi-language support) - Sentiment analysis and recommendations - User preference management (language, translation toggle, sentiment analysis toggle) - Online user status display - Offline message receipt ## Quick Start ### Environment Requirements - JDK 8+ - Maven 3.6+ - ActiveMQ 5.x ### Configuration Steps 1. Clone the project ```bash git clone https://gitee.com/hongfff/Middleware_Lab_3.git cd Middleware_Lab_3 ``` 2. Configure ActiveMQ Configure ActiveMQ connection details in `application.yml`: ```yaml spring: activemq: broker-url: tcp://localhost:61616 user: admin password: admin ``` 3. Configure translation and sentiment analysis services (optional) ```yaml tencent: cloud: secret-id: your-secret-id secret-key: your-secret-key sentiment: api: key: your-api-key ``` 4. Build and run ```bash ./mvnw spring-boot:run ``` ## Usage Instructions ### Starting the Service The service runs by default at `http://localhost:8080`. Open `src/main/resources/index.html` to access the chat interface. ### WebSocket Connection ``` ws://localhost:8080/wx ``` ### REST API Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/api/chat/send` | POST | Send a message | | `/api/chat/receive` | GET | Receive messages | | `/api/chat/online` | GET | Get online users | | `/api/chat/health` | GET | Health check | | `/api/user/preference` | POST | Set preferences | | `/api/user/preference` | GET | Get preferences | | `/api/user/preference` | PUT | Update preferences | ### Message Format ```json { "fromUser": "user1", "toUser": "user2", "content": "Hello", "type": "text" } ``` ## Configuration Reference | Configuration Key | Description | Default Value | |-------------------|-------------|---------------| | `server.port` | Server port | 8080 | | `spring.activemq.broker-url` | ActiveMQ address | tcp://localhost:61616 | | `tencent.cloud.secret-id` | Tencent Cloud SecretId | - | | `tencent.cloud.secret-key` | Tencent Cloud SecretKey | - | | `sentiment.api.key` | Sentiment Analysis API Key | - | ## Project Structure ``` src/main/java/com/middlewarelab3server/ ├── MiddlewareLab3ServerApplication.java # Main application class ├── config/ # Configuration classes │ ├── ActiveMQConfig.java │ └── WebSocketConfig.java ├── controller/ # Controllers │ ├── ChatController.java │ └── UserPreferenceController.java ├── model/ # Data models │ ├── ChatMessage.java │ └── UserPreference.java ├── service/ # Business services │ ├── ChatService.java │ ├── SentimentAnalysisService.java │ ├── TranslationService.java │ └── UserPreferenceService.java └── websocket/ # WebSocket handlers └── ChatWebSocketHandler.java ``` ## License This project is intended solely for learning and communication purposes.