Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
system
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
_site-res
system
Commits
5c94886a
Commit
5c94886a
authored
May 03, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增客户端读取服务请求参数逻辑
parent
aeb01c63
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
6 deletions
+59
-6
ThriftServiceFactoryProxy.php
classes/fpf/thrift/ThriftServiceFactoryProxy.php
+51
-1
composer.json
composer.json
+1
-0
thrift_service.php
config/thrift_service.php
+7
-5
No files found.
classes/fpf/thrift/ThriftServiceFactoryProxy.php
View file @
5c94886a
...
...
@@ -2,6 +2,10 @@
namespace
fpf\thrift
;
use
Yii
;
use
fpf\response\ResponseApi
;
use
fpf\response\BaseConstant
;
class
ThriftServiceFactoryProxy
{
private
$instance
=
null
;
...
...
@@ -17,7 +21,30 @@ class ThriftServiceFactoryProxy
self
::
BINARY
=>
'application/thrift-binary'
,
self
::
JSON
=>
'application/thrift-json'
,
];
$this
->
socket
=
new
THttpClient
(
'service.local.zhaobi.com'
,
80
,
'/market/BaseMarketService/'
);
$check_ret
=
$this
->
checkService
(
$class_name
);
if
(
true
===
$check_ret
[
BaseConstant
::
ERROR
])
{
throw
new
\Exception
(
$check_ret
[
BaseConstant
::
MSG
]);
}
$service_default_protocol
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_protocol'
,
'thrift_service'
);
$service_default_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_hosts'
,
'thrift_service'
);
$service_default_failure_policy
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_default_failure_policy'
,
'thrift_service'
);
$service_module_hosts
=
Yii
::
$app
->
fpf
->
getConfig
(
'service_module_hosts'
,
'thrift_service'
);
$service_check_arr
=
$check_ret
[
BaseConstant
::
MSG
];
$service_name_space_str
=
$service_check_arr
[
0
];
$service_str
=
$service_check_arr
[
1
];
if
(
empty
(
$service_module_hosts
[
$service_name_space_str
.
'-'
.
$service_str
]))
{
$service_config
=
$service_default_hosts
;
}
else
{
$service_config
=
$service_module_hosts
[
$service_name_space_str
.
'-'
.
$service_str
];
}
$count_service
=
count
(
$service_config
);
if
(
$count_service
>
1
)
{
$service_index
=
rand
(
0
,
$count_service
-
1
);
}
else
{
$service_index
=
0
;
}
$service_real
=
$service_config
[
$service_index
];
$this
->
socket
=
new
THttpClient
(
$service_real
[
'host'
],
$service_real
[
'port'
],
'/'
.
$service_name_space_str
.
'/'
.
$service_str
.
'/'
);
$this
->
socket
->
addHeaders
([
'Content-type'
=>
$content_type_mapping
[
$content_type
]]);
$this
->
transport
=
new
\Thrift\Transport\TBufferedTransport
(
$this
->
socket
,
1024
,
1024
);
if
(
self
::
BINARY
===
$content_type
)
{
...
...
@@ -28,6 +55,29 @@ class ThriftServiceFactoryProxy
$this
->
instance
=
new
$class_name
(
$protocol
);
}
private
function
checkService
(
$class_name
)
{
$tem_arr
=
explode
(
'\\'
,
trim
(
$class_name
,
'\\'
));
$error
=
''
;
if
(
3
!==
count
(
$tem_arr
))
{
$error
=
'service split must be have 3 items'
;
goto
doEnd
;
}
if
(
'service'
!==
$tem_arr
[
0
])
{
$error
=
'service first spit item must be \'service\''
;
goto
doEnd
;
}
if
(
!
preg_match
(
"/^([a-zA-Z0-9])+Client$/"
,
$class_name
[
2
],
$matches
))
{
$error
=
'service must ending with \'Client\''
;
goto
doEnd
;
}
doEnd
:
if
(
$error
)
{
return
ResponseApi
::
arrFail
(
$error
);
}
return
ResponseApi
::
arrSuccess
([
$tem_arr
[
1
],
$matches
[
1
]]);
}
public
function
__call
(
$name
,
$arguments
)
{
$this
->
transport
->
open
();
...
...
composer.json
View file @
5c94886a
{
"name"
:
"system"
,
"type"
:
"library"
,
"description"
:
"一些公司内部开发的类"
,
"require"
:
{},
"require-dev"
:
{},
"repositories"
:
{},
...
...
config/thrift_service.php
View file @
5c94886a
...
...
@@ -2,11 +2,13 @@
$service_domain_name
=
'service.local.zhaobi.com'
;
//$service_domain_name = 'service.local.zhaobi.com';
//$service_domain_name = 'service.zhaobi.com';
$config
[
'service_default_protocol'
]
=
'binary'
;
// binary json
$service_default_hosts
=
[
[
'host'
=>
$service_domain_name
,
'port'
=>
80
,
'timeout'
=>
10
,
'connect_timeout'
=>
100
,
'request_timeout'
=>
200
]
$config
[
'service_default_protocol'
]
=
0
;
// 0:binary 1:json
$config
[
'service_default_hosts'
]
=
[
[
'host'
=>
$service_domain_name
,
'port'
=>
80
,
'timeout'
=>
10
,
'connect_timeout'
=>
100
,
'request_timeout'
=>
200
,
'protocol'
=>
0
],
];
$config
[
'service_default_hostname'
]
=
$service_domain_name
;
$config
[
'service_default_failure_policy'
]
=
[
'default_connect_timeout'
=>
1000
,
// ms
'default_request_timeout'
=>
2000
,
// ms
...
...
@@ -14,4 +16,4 @@ $config['service_default_failure_policy'] = [
'failover_retry_times'
=>
2
,
'final_fail_return'
=>
'false'
,
// false or exception, 返回false或者抛异常
];
$config
[
'service_module_hosts'
][
'market-BaseMarketService'
]
=
$
service_default_hosts
;
$config
[
'service_module_hosts'
][
'market-BaseMarketService'
]
=
$
config
[
'service_default_hosts'
]
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment