Laravel + grpc - Laravel 5.7 gRPC Integration

Skiy 3月前 55

遇到一些问题:


解决方式:

https://stackoverflow.com/questions/54016622/laravel-5-7-grpc-integration 


如何在 Laravel 5.7 中使用 protoc 生成的文件?


1. Prepare your .proto file describing your services as you would normally do

2. Set as package name package app.grpc

3. Run the generation command: protoc --php_out=./  --grpc_out=./  --plugin=protoc-gen-grpc=/your/path/to/grpc_php_plugin yourfile.proto

4. Now copy App/Grpc inside laravel app

5. Copy GPBMetadata folder as new folder in laravel root

6. Change composer.json file inserting GPBMetadata location in the autoload classmap section (see below)

7. Run command composer dump-autoload

8. Now you can use your generated classes in any controller, remember to add use App\Grpc\YourClassName at the top.


修改 composer.json

...

    "autoload": {

        "classmap": [

            "database/seeds",

            "database/factories",

            "GPBMetadata"

        ],

        "psr-4": {

            "App\\": "app/"

        }

    }

    "require": {

        "grpc/grpc": "^v1.3.0",

        "google/protobuf": "^v3.3.0"

    },

...    


最新回复 (1)
  • Skiy 3月前
    引用 2
    注意 composer.json 中 gprc, 和 protobuf 的版本必须如以下:

            "grpc/grpc": "^v1.3.0",
            "google/protobuf": "^v3.3.0"
返回
发新帖