Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
89759be7
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
89759be7
编写于
5月 05, 2017
作者:
S
shenhongxi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grpc interface,service,client
上级
1ab57d4d
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
334 addition
and
7 deletion
+334
-7
pom.xml
pom.xml
+3
-0
whatsmars-grpc-client/pom.xml
whatsmars-grpc-client/pom.xml
+71
-0
whatsmars-grpc-client/src/main/java/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
...va/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
+44
-0
whatsmars-grpc-interface/pom.xml
whatsmars-grpc-interface/pom.xml
+66
-0
whatsmars-grpc-interface/src/main/proto/helloworld.proto
whatsmars-grpc-interface/src/main/proto/helloworld.proto
+24
-0
whatsmars-grpc-service/pom.xml
whatsmars-grpc-service/pom.xml
+44
-0
whatsmars-grpc-service/src/main/java/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
...va/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
+56
-0
whatsmars-grpc-service/src/main/java/com/itlong/whatsmars/grpc/service/impl/HelloServiceImpl.java
.../itlong/whatsmars/grpc/service/impl/HelloServiceImpl.java
+19
-0
whatsmars-grpc/src/main/java/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
...va/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
+3
-3
whatsmars-grpc/src/main/java/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
...va/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
+3
-3
whatsmars-grpc/src/main/proto/helloworld.proto
whatsmars-grpc/src/main/proto/helloworld.proto
+1
-1
未找到文件。
pom.xml
浏览文件 @
89759be7
...
...
@@ -22,6 +22,9 @@
<module>
whatsmars-spring
</module>
<module>
whatsmars-spring-boot
</module>
<module>
whatsmars-grpc
</module>
<module>
whatsmars-grpc-interface
</module>
<module>
whatsmars-grpc-service
</module>
<module>
whatsmars-grpc-client
</module>
</modules>
<properties>
...
...
whatsmars-grpc-client/pom.xml
0 → 100644
浏览文件 @
89759be7
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-parent
</artifactId>
<groupId>
com.itlong
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-grpc-client
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-netty
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-protobuf
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-stub
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
com.itlong
</groupId>
<artifactId>
whatsmars-grpc-interface
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
<extensions>
<extension>
<groupId>
kr.motd.maven
</groupId>
<artifactId>
os-maven-plugin
</artifactId>
<version>
1.4.1.Final
</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>
org.xolstice.maven.plugins
</groupId>
<artifactId>
protobuf-maven-plugin
</artifactId>
<version>
0.5.0
</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>
grpc-java
</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>
compile
</goal>
<goal>
compile-custom
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
whatsmars-grpc-client/src/main/java/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
0 → 100644
浏览文件 @
89759be7
package
com.itlong.whatsmars.grpc.client
;
import
com.itlong.whatsmars.grpc.service.HelloRequest
;
import
com.itlong.whatsmars.grpc.service.HelloResponse
;
import
com.itlong.whatsmars.grpc.service.HelloServiceGrpc
;
import
io.grpc.ManagedChannel
;
import
io.grpc.ManagedChannelBuilder
;
import
java.util.concurrent.TimeUnit
;
/**
* Created by shenhongxi on 2017/5/5.
*/
public
class
HelloWorldClient
{
private
final
ManagedChannel
channel
;
private
final
HelloServiceGrpc
.
HelloServiceBlockingStub
blockingStub
;
public
HelloWorldClient
(
String
host
,
int
port
){
channel
=
ManagedChannelBuilder
.
forAddress
(
host
,
port
)
.
usePlaintext
(
true
)
.
build
();
blockingStub
=
HelloServiceGrpc
.
newBlockingStub
(
channel
);
}
public
void
shutdown
()
throws
InterruptedException
{
channel
.
shutdown
().
awaitTermination
(
5
,
TimeUnit
.
SECONDS
);
}
public
void
greet
(
String
name
){
HelloRequest
request
=
HelloRequest
.
newBuilder
().
setName
(
name
).
build
();
HelloResponse
response
=
blockingStub
.
sayHello
(
request
);
System
.
out
.
println
(
response
.
getMessage
());
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
HelloWorldClient
client
=
new
HelloWorldClient
(
"127.0.0.1"
,
50051
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
client
.
greet
(
"world:"
+
i
);
}
client
.
shutdown
();
}
}
whatsmars-grpc-interface/pom.xml
0 → 100644
浏览文件 @
89759be7
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-parent
</artifactId>
<groupId>
com.itlong
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-grpc-interface
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-netty
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-protobuf
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-stub
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
<extensions>
<extension>
<groupId>
kr.motd.maven
</groupId>
<artifactId>
os-maven-plugin
</artifactId>
<version>
1.4.1.Final
</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>
org.xolstice.maven.plugins
</groupId>
<artifactId>
protobuf-maven-plugin
</artifactId>
<version>
0.5.0
</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>
grpc-java
</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>
compile
</goal>
<goal>
compile-custom
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
whatsmars-grpc-interface/src/main/proto/helloworld.proto
0 → 100644
浏览文件 @
89759be7
syntax
=
"proto3"
;
option
java_multiple_files
=
true
;
option
java_package
=
"com.itlong.whatsmars.grpc.service"
;
option
java_outer_classname
=
"HelloWorldProto"
;
option
objc_class_prefix
=
"HLW"
;
package
helloworld
;
// The greeting service definition.
service
HelloService
{
// Sends a greeting
rpc
sayHello
(
HelloRequest
)
returns
(
HelloResponse
)
{}
}
// The request message containing the user's name.
message
HelloRequest
{
string
name
=
1
;
}
// The response message containing the greetings
message
HelloResponse
{
string
message
=
1
;
}
\ No newline at end of file
whatsmars-grpc-service/pom.xml
0 → 100644
浏览文件 @
89759be7
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-parent
</artifactId>
<groupId>
com.itlong
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-grpc-service
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-netty
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-protobuf
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
io.grpc
</groupId>
<artifactId>
grpc-stub
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
com.itlong
</groupId>
<artifactId>
whatsmars-grpc-interface
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
</build>
</project>
\ No newline at end of file
whatsmars-grpc-service/src/main/java/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
0 → 100644
浏览文件 @
89759be7
package
com.itlong.whatsmars.grpc.server
;
import
com.itlong.whatsmars.grpc.service.impl.HelloServiceImpl
;
import
io.grpc.Server
;
import
io.grpc.ServerBuilder
;
import
java.io.IOException
;
/**
* Created by shenhongxi on 2017/5/5.
*/
public
class
HelloWorldServer
{
private
int
port
=
50051
;
private
Server
server
;
private
void
start
()
throws
IOException
{
server
=
ServerBuilder
.
forPort
(
port
)
.
addService
(
new
HelloServiceImpl
())
.
build
()
.
start
();
System
.
out
.
println
(
"service start..."
);
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
()
{
@Override
public
void
run
()
{
System
.
err
.
println
(
"*** shutting down gRPC server since JVM is shutting down"
);
HelloWorldServer
.
this
.
stop
();
System
.
err
.
println
(
"*** server shut down"
);
}
});
}
private
void
stop
()
{
if
(
server
!=
null
)
{
server
.
shutdown
();
}
}
// block 一直到退出程序
private
void
blockUntilShutdown
()
throws
InterruptedException
{
if
(
server
!=
null
)
{
server
.
awaitTermination
();
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
final
HelloWorldServer
server
=
new
HelloWorldServer
();
server
.
start
();
server
.
blockUntilShutdown
();
}
}
whatsmars-grpc-service/src/main/java/com/itlong/whatsmars/grpc/service/impl/HelloServiceImpl.java
0 → 100644
浏览文件 @
89759be7
package
com.itlong.whatsmars.grpc.service.impl
;
import
com.itlong.whatsmars.grpc.service.HelloRequest
;
import
com.itlong.whatsmars.grpc.service.HelloResponse
;
import
com.itlong.whatsmars.grpc.service.HelloServiceGrpc
;
import
io.grpc.stub.StreamObserver
;
/**
* Created by shenhongxi on 2017/5/5.
*/
public
class
HelloServiceImpl
extends
HelloServiceGrpc
.
HelloServiceImplBase
{
public
void
sayHello
(
HelloRequest
req
,
StreamObserver
<
HelloResponse
>
responseObserver
)
{
System
.
out
.
println
(
"service:"
+
req
.
getName
());
HelloResponse
response
=
HelloResponse
.
newBuilder
().
setMessage
((
"Hello: "
+
req
.
getName
())).
build
();
responseObserver
.
onNext
(
response
);
responseObserver
.
onCompleted
();
}
}
whatsmars-grpc/src/main/java/com/itlong/whatsmars/grpc/client/HelloWorldClient.java
浏览文件 @
89759be7
...
...
@@ -2,7 +2,7 @@ package com.itlong.whatsmars.grpc.client;
import
io.grpc.ManagedChannel
;
import
io.grpc.ManagedChannelBuilder
;
import
com.itlong.whatsmars.grpc.service.
Greeter
Grpc
;
import
com.itlong.whatsmars.grpc.service.
HelloService
Grpc
;
import
com.itlong.whatsmars.grpc.service.HelloRequest
;
import
com.itlong.whatsmars.grpc.service.HelloResponse
;
...
...
@@ -14,14 +14,14 @@ import java.util.concurrent.TimeUnit;
public
class
HelloWorldClient
{
private
final
ManagedChannel
channel
;
private
final
GreeterGrpc
.
Greeter
BlockingStub
blockingStub
;
private
final
HelloServiceGrpc
.
HelloService
BlockingStub
blockingStub
;
public
HelloWorldClient
(
String
host
,
int
port
){
channel
=
ManagedChannelBuilder
.
forAddress
(
host
,
port
)
.
usePlaintext
(
true
)
.
build
();
blockingStub
=
Greeter
Grpc
.
newBlockingStub
(
channel
);
blockingStub
=
HelloService
Grpc
.
newBlockingStub
(
channel
);
}
public
void
shutdown
()
throws
InterruptedException
{
...
...
whatsmars-grpc/src/main/java/com/itlong/whatsmars/grpc/server/HelloWorldServer.java
浏览文件 @
89759be7
...
...
@@ -3,7 +3,7 @@ package com.itlong.whatsmars.grpc.server;
import
io.grpc.Server
;
import
io.grpc.ServerBuilder
;
import
io.grpc.stub.StreamObserver
;
import
com.itlong.whatsmars.grpc.service.
Greeter
Grpc
;
import
com.itlong.whatsmars.grpc.service.
HelloService
Grpc
;
import
com.itlong.whatsmars.grpc.service.HelloRequest
;
import
com.itlong.whatsmars.grpc.service.HelloResponse
;
...
...
@@ -19,7 +19,7 @@ public class HelloWorldServer {
private
void
start
()
throws
IOException
{
server
=
ServerBuilder
.
forPort
(
port
)
.
addService
(
new
Greeter
Impl
())
.
addService
(
new
HelloService
Impl
())
.
build
()
.
start
();
...
...
@@ -57,7 +57,7 @@ public class HelloWorldServer {
}
// 实现 定义一个实现服务接口的类
private
class
GreeterImpl
extends
GreeterGrpc
.
Greeter
ImplBase
{
private
class
HelloServiceImpl
extends
HelloServiceGrpc
.
HelloService
ImplBase
{
public
void
sayHello
(
HelloRequest
req
,
StreamObserver
<
HelloResponse
>
responseObserver
)
{
System
.
out
.
println
(
"service:"
+
req
.
getName
());
...
...
whatsmars-grpc/src/main/proto/helloworld.proto
浏览文件 @
89759be7
...
...
@@ -8,7 +8,7 @@ option objc_class_prefix = "HLW";
package
helloworld
;
// The greeting service definition.
service
Greeter
{
service
HelloService
{
// Sends a greeting
rpc
sayHello
(
HelloRequest
)
returns
(
HelloResponse
)
{}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录