# Hyperf之Grpc微服务框架V3.0 **Repository Path**: trident-framework/hyperf-micro-grpc-v3.0 ## Basic Information - **Project Name**: Hyperf之Grpc微服务框架V3.0 - **Description**: Hyperf grpc微服务框架V3.0 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2024-10-21 - **Last Updated**: 2025-09-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hyperf Micro gRPC Project Documentation ## Introduction This project is a gRPC service project built using the [Hyperf](https://github.com/hyperf/hyperf) framework within a microservices architecture. It includes multiple service modules, such as the user service (`user-service`) and gateway service (`gateway-api`), making it suitable for building high-performance distributed systems. The project uses gRPC for inter-service communication and combines Protobuf to define service interfaces and data structures, providing efficient and reliable service invocation capabilities. ## System Requirements - PHP >= 8.0 - Swoole PHP Extension >= 4.5 (recommended; set `swoole.use_shortname = Off` in `php.ini`) - OpenSSL PHP Extension (required for HTTPS support) - PDO PHP Extension (required for MySQL client support) - Redis PHP Extension (required for Redis client support) - Protobuf PHP Extension (required for gRPC service or client usage) - Docker (optional, for quick deployment) ## Installation and Deployment ### Creating the Project with Composer ```bash $ composer create-project hyperf/hyperf-skeleton path/to/install ``` ### Starting the Service Navigate to the project directory and start the Hyperf service: ```bash $ cd path/to/install $ php bin/hyperf.php start ``` By default, the service runs on port `9501` and binds to all network interfaces. You can access the default homepage by visiting `http://localhost:9501/`. ### Deploying with Docker We provide a Dockerfile and docker-compose configuration files for quick deployment in development, testing, and production environments. 1. Build the Docker image: ```bash $ docker build -t hyperf-micro-grpc . ``` 2. Start the container: ```bash $ docker run -d -p 9501:9501 hyperf-micro-grpc ``` Or use `docker-compose`: ```bash $ docker-compose up -d ``` ## Project Structure Overview The project is primarily divided into the following modules: - **gateway-api**: Gateway service that provides external RESTful API interfaces and integrates gRPC clients to call internal services. - **user-service**: User service that provides fundamental functionalities such as user management, address management, and shopping cart operations, offering service interfaces via gRPC. ### Main Directory Structure - `app/Controller`: API controllers for handling HTTP requests. - `app/Grpc`: gRPC service interface definitions and client invocation logic. - `app/Model`: Database models for data persistence. - `app/Logic`: Business logic layer for encapsulating core business logic. - `config/autoload`: Configuration files directory, including configurations for databases, gRPC, caching, etc. - `proto`: Protobuf interface definition files (`.proto`) used to generate gRPC interface code. - `public`: Static resource directory. - `Dockerfile`: Docker build file. - `docker-compose.yaml`: Docker Compose configuration file for multi-container deployments. ## Service Overview ### Gateway Service (`gateway-api`) The gateway service acts as the entry point of the system, responsible for receiving HTTP requests and invoking internal service modules via gRPC. It integrates the following features: - User authentication (JWT) - Rate limiting - File upload (supports local storage, MinIO, and OSS) - Message queue (RabbitMQ) - Search service (Elasticsearch) - Distributed transactions (DTM) ### User Service (`user-service`) The user service provides fundamental functionalities such as user management, address management, and shopping cart operations. It exposes service interfaces via gRPC for invocation by other services. - User registration, login, and profile management - User address management (CRUD operations) - Shopping cart management (CRUD operations, batch processing) ## gRPC Interface Definitions gRPC interface definitions are located in `.proto` files within the `proto` directory, including: - `user.proto`: User service interface definition - `userAddress.proto`: User address service interface definition - `userCart.proto`: User shopping cart service interface definition - `params.proto`: Common parameter definitions - `result.proto`: Common result response definitions ## Development and Debugging ### Dependency Management Use Composer to manage project dependencies: ```bash $ composer install ``` ### Configuration Files - `.env.dev` / `.env.prod` / `.env.test`: Environment-specific configuration files - `config/autoload`: Hyperf auto-loaded configuration files, such as database, gRPC, and cache configurations ### Logging and Debugging - **Log Output**: `app/Exception/Handler/AppExceptionHandler.php` handles global exception handling and logging. - **Unit Testing**: PHPUnit test cases are located in the `test/` directory. ## Service Startup and Execution ### Starting the Service ```bash $ php bin/hyperf.php start ``` ### Stopping the Service ```bash $ php bin/hyperf.php stop ``` ### Restarting the Service ```bash $ php bin/hyperf.php reload ``` ## Service Interface Documentation All gRPC interface definitions are located in the `proto` directory. Client and server code can be generated using the `protoc` tool. ## Contributing and Maintenance Contributions of code and issue reports are welcome. Please follow the project's coding standards and submit Pull Requests to the main repository. ## License This project uses the [MIT License](https://opensource.org/licenses/MIT). For details, please refer to the `LICENSE` file.