1.0 RPC
If the system was previously using the Swoft 1.0 RPC server, Swoft 2.0 defines a compatible 1.0 RPC protocol that is easy to use.
Available:
>= v2.0.3
Configuration
To use the services provided by the 1.0 RPC server in the 2.0 framework, you must first configure (app/bean.php) 1.0 RPC protocol.
return [
// ...
'user' => [
'class' => ServiceClient::class,
'host' => '127.0.0.1',
'port' => 8099,
'setting' => [
'timeout' => 0.5,
'connect_timeout' => 1.0,
'write_timeout' => 10.0,
'read_timeout' => 0.5,
'package_eof' => "\r\n",
],
'packet' => bean('rpcClientSwoftPacketV1')
],
// ...
];
- Host/port configuration 1.0 address and port
- Package_eof must be configured with the end of the packet, 1.0 end of the package is
\r\n
- Packet must be configured to use the
bean('rpcClientSwoftPacketV1')
1.0 packer
use
After the above configuration is completed, it can be used directly. Here is an example of calling App\Lib\DemoInterface
Swoft 1.x:
/**
* Class RpcController
*
* @since 2.0
*
* @Controller()
*/
class RpcController
{
/**
* @Reference(pool="user.pool", version="0")
*
* @var DemoInterface
*/
private $demoServcie;
/**
* @RequestMapping(route="swoftV1")
*
* @return array
*/
public function swoftV1():array {
return [$this->demoServcie->getUser('1')];
}
}
- Calling 1.x RPC
version
must be specified because 2.x is not the same as 1.0 default - Cannot call 1.x's
deferXxxx
method 2.0 has been dropped - The interface called in 2.x must be exactly the same as the 1.x interface namespace, class name, and method name parameters.