Swoft 2.0.6 how to implement Rpc service client and non-Swoft framework external invocation
This article mainly introduces "how Swoft 2.0.6 implements Rpc service client and non-Swoft framework external invocation". In daily operations, I believe many people have doubts about how to implement Rpc service client and non-Swoft framework external invocation in Swoft 2.0.6. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the question of "how to implement Rpc service client and non-Swoft framework external invocation with Swoft 2.0.6"! Next, please follow the editor to study!
1. Start the http and rpc services first.
I use docker-compose directly to start the service here.
You can also enter the swoft container and use the command to open the service.
Http command: php bin/swoft http:start
Rpc command: php bin/swoft rpc:start
2.RPC Server configuration parameters
There are two ways to start RPC services: start separately and integrate other services (Http/Websocket). Either way, you have to configure RPC in bean.php first.
'rpcServer' = > [' class' = > ServiceServer::class, 'port' = > 18307,]
The RPC service is integrated in 3.Http server startup. Its listener listens to a single RPC service and can listen to multiple RPC services at the same time.
'httpServer' = > [' class' = > HttpServer::class, 'port' = > 18306,' listener' = > ['rpc' = > bean (' rpcServer')], 'process' = > [/ /' monitor' = > bean (MonitorProcess::class) / / 'crontab' = > bean (CrontabProcess::class)] 'on' = > [/ / SwooleEvent::TASK = > bean (SyncTaskListener::class), / / Enable sync task SwooleEvent::TASK = > bean (TaskListener::class), / / Enable task must task and finish event SwooleEvent::FINISH = > bean (FinishListener::class)] / * @ see HttpServer::$setting * / 'setting' = > [' task_worker_num' = > 12, 'task_enable_coroutine' = > true,' worker_num' = > 6]]
5. Define the interface and implement the interface to provide RPC services. Note the version number customized note @ Service ()
6. Define Interfac