zoukankan      html  css  js  c++  java
  • http服务调用tcp服务

    参考 https://github.com/TarsCloud/TarsDocs/blob/master/hello-world/tarsphp.md#chapter-3

    现在有了一个HTTP服务,还有一个Tars的TCP服务,如何用HTTP服务里调用TCP服务呢?

    将Tars服务的TCPServer.tars 复制到 Http服务的tars目录里

    在Http服务里创建 tars/tarsclient.proto.php

    <?php
    /**
     * Created by PhpStorm.
     * User: liangchen
     * Date: 2018/2/24
     * Time: 下午3:43.
     */
    
    return array(
        'appName' => 'HelloWorld',
        'serverName' => 'TCPServer',
        'objName' => 'obj',
        'withServant' => false, //决定是服务端,还是客户端的自动生成
        'tarsFiles' => array(
            './TCPServer.tars',
        ),
        'dstPath' => '../src/servant',
        'namespacePrefix' => 'HttpServerservant',
    );
    
    

    执行cd scripts && ./tars2php.sh生成客户端调用代码

    会生成对应的servant代码

    在IndexController 新增方法

     public function actionTestGreeting()
        {
            $config = new TarsclientCommunicatorConfig();
            $config->setLocator(TarsApp::$tarsConfig['tars']['application']['client']['locator']);
    
            $userService = new HttpServerservantHelloWorldTCPServerobjTestTafServiceServant($config);
            $greeting = '';
            $return = $userService->sayHelloWorld('Frank Lee', $greeting);
    
            $this->sendRaw(json_encode(compact('return', 'greeting')));
        }
    

    重新发布http服务 访问此方法 调用成功

  • 相关阅读:
    ubuntu svn
    node install
    Hello World
    复合过去式
    Fréquence
    HTTP是什么?
    Photon——Requirements 需求
    Ext.Net 实现文件下载
    我的绝世好剑——如何开始创建.NET程序
    Photon——Introduction 介绍
  • 原文地址:https://www.cnblogs.com/webclz/p/13547492.html
Copyright © 2011-2022 走看看