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'[101]
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
Read More:
- PHP error in Windows: class’ mysqli ‘not found
- [Solved] PHP Fatal error: Uncaught Error: Class ‘Redis‘ not found in
- Mac PHP Fatal error: Class ‘Memcache’ not found
- [Solved] Fatal error: Uncaught Error: Class ‘Imagick‘ not found
- [Solved] Fatal error: Class ‘think\Container‘ not found & [InvalidArgumentException] Could not find package
- [Solved] Laravel admin Error: Symfony\Component\Debug\Exception\FatalThrowableError : Class ‘Doctrine\DBAL\Driver\PDOMySql\Driver’ not found
- How to Solve PHP Error: no package’oniguruma’ found
- Mac installs the php Swoole extension and appears Enable openssl support, require openssl library or fatal error:’openssl/ssl.h’ file not found
- /www/server/php/56/sbin/php-fpm:error while loading shared libraries:libssl.so.1.0. 0:cannot open shared object file:No such file or directory
- [PHP] __autoload function will be called when class_exists does not exist
- PHP Error Object of class mysqli could not be converted to string in
- Hyperf [ERROR] Invalid protocol of registry consul[205]
- [Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
- laravel The Process class relies on proc_open, which is not available on your PHP installation.
- [Solved] PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes
- composer Error: The requested PHP extension ext-bcmath * is missing from your system. Install or enable
- Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k
- [Solved] PostgreSQL configure: error: readline library not found
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- [Solved] Artisan error: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes