2017 © Pedro Peláez
 

project service

Uniondrug Micro Service Component for uniondrug/framework

image

uniondrug/service

Uniondrug Micro Service Component for uniondrug/framework

  • Tuesday, May 22, 2018
  • by wsfuyibing
  • Repository
  • 2 Watchers
  • 0 Stars
  • 618 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 23 Versions
  • 53 % Grown

The README.md

药联微服务协议封装

Uniondrug微服务服务端和客户端的封装。基于HTTP的微服务报文格式形如:, (*1)

{
    "errno": "0",
    "error": "",
    "dataType": "OBJECT",
    "data": {
        "do2": {
            "from": "do1"
        },
        "do3": {
            "from": "do1"
        }
    }
}

通过封装后,在服务端,通过Server的系列方法直接产生上述格式的响应报文。在客户端,通过Client的方法,发起请求,对上述报文自动解析封装,方便使用。, (*2)

安装

$ cd project-home
$ composer require uniondrug/service

修改 app.php 配置文件,注入服务。服务名称:服务端 serviceServer,客户端 serviceClient。, (*3)

return [
    'default' => [
        ......
        'providers'           => [
            ......
            \Uniondrug\Service\ServiceServiceProvider::class,
        ],
    ],
];

客户端(Client)

使用方法

发起请求, (*4)

方法:, (*5)

  • delete(serviceName, route, query[], body[], extra[])
  • get(serviceName, route, query[], body[], extra[])
  • head(serviceName, route, query[], body[], extra[])
  • options(serviceName, route, query[], body[], extra[])
  • patch(serviceName, route, query[], body[], extra[])
  • post(serviceName, route, query[], body[], extra[])
  • put(serviceName, route, query[], body[], extra[])

说明:, (*6)

  • serviceName 服务名称,在注册中心注册的服务名称,发起请求时,会自动从注册中心查找该服务的节点。
  • route 是服务路由,通常就是应用服务的控制器路由。比如/member/info
  • query[] 是数组格式的参数,如果有,则以QueryString的方式发送。
  • body[] 是数组格式的参数,如果有,默认以JSON的格式发送。如果想改变,则使用extra[]设定。
  • extra[] 是数组格式的参数,包括: -- type: body的发送方式,模式是json,可选的有:form: 以form-url-encoded的方式发送;multipart:以form-data的方式发送。 -- timeout: 发送请求的超时,单位秒 -- connect_timeout: 连接节点的超时时间,单位秒 -- headers: 数组,可选的头信息。

返回值, (*7)

请求成功则返回一个Uniondrug\Service\RequestReader对象:, (*8)

方法:, (*9)

  • response() 获得原始的Response对象。
  • data() 获得服务返回的结构化结果。也就是data里面的内容。
  • headers() 获得返回结果的头信息。
  • getContents() 获得返回的Body内容。
  • getDuration() 获得请求用的时间。
  • hasError() 返回结果是否有错(应用错误,而非Http请求的错误。Http请求出错,会抛出异常)。
  • getErrno() 获得错误代码
  • getError() 获得错误信息

举例:, (*10)

public function postAction()
{
    $serviceName = 'serviceName';
    $route = '/route/action';
    $query = ["page" => 1];
    $body = ["userId" => 1, "options" => ["key" => "value"]];
    $return = $this->serviceClient->post($serviceName, $route, $query, $body);

    print_r($return->data());
}

服务端

在服务端的控制器,使用Server封装产生指定格式的响应报文体。, (*11)

使用方法

方法, (*12)

  • Phalcon\Http\Response - withError(string $error, int $errno = 1)
  • Phalcon\Http\Response - withStruct(Uniondrug\Structs\StructInterface $struct)

举例, (*13)

public function postAction()
{
    // codes ignored
    $this->serviceServer->withError("错误原因", 1);
}

The Versions

22/05 2018

dev-master

9999999-dev

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by fuyibing
by Uniondrug Dev Team

phalcon

22/05 2018

2.7.7

2.7.7.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

22/05 2018

2.x-dev

2.9999999.9999999.9999999-dev

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by fuyibing
by Uniondrug Dev Team

phalcon

21/05 2018

2.7.6

2.7.6.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

18/05 2018

2.7.5

2.7.5.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

02/05 2018

2.7.4

2.7.4.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

29/04 2018

2.7.3

2.7.3.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

03/04 2018

2.7.1

2.7.1.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

03/04 2018

2.7.2

2.7.2.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

03/04 2018

2.7.0

2.7.0.0

Uniondrug Micro Service Component for uniondrug/framework

  Sources   Download

proprietary

The Requires

 

by Uniondrug Dev Team

phalcon

27/03 2018

2.6

2.6.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

27/03 2018

2.5

2.5.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

23/03 2018

2.4

2.4.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

20/03 2018

2.3

2.3.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

06/03 2018

2.2

2.2.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

01/03 2018

2.1

2.1.0.0

micro service base

  Sources   Download

proprietary

The Requires

 

by fuyibing

phalcon

27/02 2018

2.0

2.0.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

23/02 2018

1.7

1.7.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

01/02 2018

1.6

1.6.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

31/01 2018

1.5

1.5.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

22/12 2017

1.4

1.4.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

19/12 2017

1.2

1.2.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon

14/11 2017

1.1

1.1.0.0

micro service base

  Sources   Download

proprietary

by fuyibing

phalcon