An error occurs when a service consumer class is manually created for the hyperf 2.2.0 microservice.
In the documentation on the official website, when manually creating a consumer class, its recommended configuration of services.php is as follows.
<?php return [ 'consumers' => [ [ 'name' => 'CalculatorService', 'registry' => [ 'protocol' => 'consul', 'address' => 'http://127.0.0.1:8500', ], 'nodes' => [ ['host' => '127.0.0.1', 'port' => 9504], ], ] ], ];
Later, I saw the video on the official website jsonrpc. The recommendation in the video is as follows.
<?php return [ 'consumers' => [ [ 'name' => 'CalculatorService', 'nodes' => [ ['host' => '127.0.0.1', 'port' => 9504], ], ] ], ];
I wonder if the above writing is only applicable to the 1. X.x era?When I upgrade to 2.2.0, it is reported above
[ERROR] Error while injecting dependencies into App\Controller\IndexController: No entry or class found for ‘App\Rpc\CalculatorServiceInterface'
After tossing for a long time, I found that there are few services.php configurations
'service' => \App\Rpc\CalculatorServiceInterface::class,
So, don’t lose service. The complete services.php is like this
return [ 'consumers' => [ [ // name needs to be the same as the name attribute of the service provider 'name' => 'CalculatorService', // service interface name, optional, default value is equal to the value configured by name, if name is defined directly as an interface class then this line can be ignored, if name is a string then you need to configure service to correspond to the interface class 'service' => \App\Rpc\CalculatorServiceInterface::class, // corresponding to the container object ID, optional, default value is equal to the service configuration value, used to define the dependency injection key 'id' => \App\Rpc\CalculatorServiceInterface::class, // Service protocol of the service provider, optional, default value is jsonrpc-http // optional jsonrpc-http jsonrpc jsonrpc-tcp-length-check 'protocol' => 'jsonrpc-http', // load balancing algorithm, optional, default value is random // 'load_balancer' => 'random', // which service center this consumer will get the node information from, if not configured it will not get the node information from the service center // 'registry' => [ // 'protocol' => 'consul', // 'address' => 'http://127.0.0.1:8500', // ], // If the above registry configuration is not specified, i.e., the node is consumed directly for the specified node, and the node information of the service provider is configured with the following nodes parameter 'nodes' => [ ['host' => '127.0.0.1', 'port' => 9504], ], ] ], ];
Run later and run through
- nginx.conf php-fpm.conf and php.ini Error among the three_ Differences and relations between log instructions
- Laravel-admin php artisan admin:install error reporting problem solution
- [PHP] __autoload function will be called when class_exists does not exist
- Syntax error: typeerror: about installing sass in vue3 this.getOptions is not a function
- php_network_getaddresses: getaddrinfo failed (How to Fix)
- PHP Error Object of class mysqli could not be converted to string in
- PHP error in Windows: class’ mysqli ‘not found
- TP5 fuzzy Chinese characters error [How to Solve]
- Laravel5.5 Error: SQLSTATE Syntax error or access violation 1071 Specified key was too long; max k
- [PHP] Solve the limitation of uploading files in nginx php 413 Request Entity Too Large
- PHP: How to parse MHT file into HTML
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- [Solved] PHP Fatal error: Uncaught Error: Class ‘Redis‘ not found in
- Mac: Where is php.ini Location
- Using $this when not in object context in (How to Fix)
- PHP use __Sleep() and __wakeup() method serializes the object
- Leetcode 357: How to calculate the number of digits with different digits
- PHP parse error: syntax error, unexpected ‘use’
- Mac installs the php Swoole extension and appears Enable openssl support, require openssl library or fatal error:’openssl/ssl.h’ file not found
- [Solved] Request exceeded the limit of 10 internal redirects due to possible configuration error