Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
c47b0899
Commit
c47b0899
authored
5 years ago
by
xujianhai666
Browse files
Options
Downloads
Patches
Plain Diff
support grpc server
parent
35abd82c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
protocol/grpc/grpc_protocol.go
+17
-1
17 additions, 1 deletion
protocol/grpc/grpc_protocol.go
protocol/grpc/server.go
+38
-7
38 additions, 7 deletions
protocol/grpc/server.go
registry/zookeeper/registry.go
+1
-0
1 addition, 0 deletions
registry/zookeeper/registry.go
with
56 additions
and
8 deletions
protocol/grpc/grpc_protocol.go
+
17
−
1
View file @
c47b0899
...
...
@@ -45,6 +45,7 @@ type GrpcProtocol struct {
func
NewGRPCProtocol
()
*
GrpcProtocol
{
return
&
GrpcProtocol
{
BaseProtocol
:
protocol
.
NewBaseProtocol
(),
serverMap
:
make
(
map
[
string
]
*
Server
),
}
}
...
...
@@ -60,7 +61,22 @@ func (gp *GrpcProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
}
func
(
gp
*
GrpcProtocol
)
openServer
(
url
common
.
URL
)
{
return
_
,
ok
:=
gp
.
serverMap
[
url
.
Location
]
if
!
ok
{
_
,
ok
:=
gp
.
ExporterMap
()
.
Load
(
url
.
ServiceKey
())
if
!
ok
{
panic
(
"[GrpcProtocol]"
+
url
.
Key
()
+
"is not existing"
)
}
gp
.
serverLock
.
Lock
()
_
,
ok
=
gp
.
serverMap
[
url
.
Location
]
if
!
ok
{
srv
:=
NewServer
()
gp
.
serverMap
[
url
.
Location
]
=
srv
srv
.
Start
(
url
)
}
gp
.
serverLock
.
Unlock
()
}
}
func
(
gp
*
GrpcProtocol
)
Refer
(
url
common
.
URL
,
impl
interface
{})
protocol
.
Invoker
{
...
...
This diff is collapsed.
Click to expand it.
protocol/grpc/server.go
+
38
−
7
View file @
c47b0899
...
...
@@ -18,7 +18,9 @@ limitations under the License.
package
grpc
import
(
"fmt"
"net"
"reflect"
)
import
(
...
...
@@ -27,6 +29,9 @@ import (
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config"
"github.com/apache/dubbo-go/protocol"
)
type
Server
struct
{
...
...
@@ -34,11 +39,15 @@ type Server struct {
}
func
NewServer
()
*
Server
{
return
&
Server
{}
}
return
nil
type
DubboGrpcService
interface
{
SetProxyImpl
(
impl
protocol
.
Invoker
)
GetProxyImpl
()
protocol
.
Invoker
ServiceDesc
()
*
grpc
.
ServiceDesc
}
// TODO: unimplemented
func
(
s
*
Server
)
Start
(
url
common
.
URL
)
{
var
(
addr
string
...
...
@@ -51,12 +60,34 @@ func (s *Server) Start(url common.URL) {
}
server
:=
grpc
.
NewServer
()
key
:=
url
.
GetParam
(
constant
.
BEAN_NAME_KEY
,
""
)
service
:=
config
.
GetProviderService
(
key
)
ds
,
ok
:=
service
.
(
DubboGrpcService
)
if
!
ok
{
panic
(
"illegal service type registered"
)
}
m
,
ok
:=
reflect
.
TypeOf
(
service
)
.
MethodByName
(
"SetProxyImpl"
)
if
!
ok
{
panic
(
"method SetProxyImpl is necessary for grpc service"
)
}
exporter
,
_
:=
grpcProtocol
.
ExporterMap
()
.
Load
(
url
.
ServiceKey
())
if
exporter
==
nil
{
panic
(
fmt
.
Sprintf
(
"no exporter found for servicekey: %v"
,
url
.
ServiceKey
()))
}
invoker
:=
exporter
.
(
protocol
.
Exporter
)
.
GetInvoker
()
if
invoker
==
nil
{
panic
(
fmt
.
Sprintf
(
"no invoker found for servicekey: %v"
,
url
.
ServiceKey
()))
}
in
:=
[]
reflect
.
Value
{
reflect
.
ValueOf
(
service
)}
in
=
append
(
in
,
reflect
.
ValueOf
(
invoker
))
m
.
Func
.
Call
(
in
)
server
.
RegisterService
(
ds
.
ServiceDesc
(),
service
)
s
.
grpcServer
=
server
// grpc-go 必须提前注册
// ServiceDesc 这个信息需要有
// 需要找一个方法。
//server.RegisterService()
// 想个办法注册下
if
err
=
server
.
Serve
(
lis
);
err
!=
nil
{
panic
(
err
)
}
...
...
This diff is collapsed.
Click to expand it.
registry/zookeeper/registry.go
+
1
−
0
View file @
c47b0899
...
...
@@ -370,6 +370,7 @@ func (r *zkRegistry) register(c common.URL) error {
return
perrors
.
Errorf
(
"@c{%v} type is not referencer or provider"
,
c
)
}
dubboPath
=
strings
.
ReplaceAll
(
dubboPath
,
"$"
,
"%24"
)
err
=
r
.
registerTempZookeeperNode
(
dubboPath
,
encodedURL
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment