-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add gRPC java samples #419
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://github.com/GoogleCloudPlatform/openjdk-runtime | ||
FROM gcr.io/google_appengine/openjdk8 | ||
|
||
RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list \ | ||
&& apt-get update \ | ||
&& apt-get install --no-install-recommends -y -q ca-certificates \ | ||
&& apt-get -y -q upgrade \ | ||
&& apt-get install --no-install-recommends -y openjdk-8-jre-headless \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ADD ./server/build/libs/server.jar /bookstore/server.jar | ||
|
||
EXPOSE 8000 | ||
|
||
ENTRYPOINT ["java", "-jar", "/bookstore/server.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Google Cloud Endpoints Bookstore App in Java | ||
|
||
## Prerequisites | ||
|
||
* [Java 8](http://openjdk.java.net/install/) | ||
* [Docker](https://www.docker.com/products/docker) | ||
|
||
## Building and Running the Server | ||
|
||
The Java Bookstore gRPC example is built using Gradle: | ||
|
||
./gradlew build | ||
|
||
To run the Java server and client locally: | ||
|
||
# Start the server (listens on port 8000 by default) | ||
java -jar ./server/build/libs/server.jar | ||
|
||
# Run the client (connects to localhost:8000 by default) | ||
java -jar ./client/build/libs/client.jar | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
apply plugin: 'java' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have a copyright at top. I'm Ok with this being in Gradle, but using maven in our repo runs checkstyle and other things to keep stuff in shape. |
||
apply plugin: 'com.google.protobuf' | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0' | ||
|
||
} | ||
} | ||
|
||
dependencies { | ||
repositories { | ||
mavenCentral() | ||
} | ||
compile 'io.grpc:grpc-netty:1.0.1' | ||
compile 'io.grpc:grpc-protobuf:1.0.1' | ||
compile 'io.grpc:grpc-stub:1.0.1' | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
artifact = 'com.google.protobuf:protoc:3.0.2' | ||
} | ||
|
||
plugins { | ||
grpc { | ||
artifact = 'io.grpc:protoc-gen-grpc-java:1.0.1' | ||
} | ||
} | ||
generateProtoTasks { | ||
all()*.plugins { | ||
grpc {} | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
endpoints/bookstore-grpc/api/src/main/proto/bookstore.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
syntax = "proto3"; | ||
|
||
package endpoints.examples.bookstore; | ||
|
||
option java_multiple_files = true; | ||
option java_outer_classname = "BookstoreProto"; | ||
option java_package = "com.google.endpoints.examples.bookstore"; | ||
|
||
|
||
import "google/protobuf/empty.proto"; | ||
|
||
// A simple Bookstore API. | ||
// | ||
// The API manages shelves and books resources. Shelves contain books. | ||
service Bookstore { | ||
// Returns a list of all shelves in the bookstore. | ||
rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) {} | ||
// Creates a new shelf in the bookstore. | ||
rpc CreateShelf(CreateShelfRequest) returns (Shelf) {} | ||
// Returns a specific bookstore shelf. | ||
rpc GetShelf(GetShelfRequest) returns (Shelf) {} | ||
// Deletes a shelf, including all books that are stored on the shelf. | ||
rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {} | ||
// Returns a list of books on a shelf. | ||
rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {} | ||
// Creates a new book. | ||
rpc CreateBook(CreateBookRequest) returns (Book) {} | ||
// Returns a specific book. | ||
rpc GetBook(GetBookRequest) returns (Book) {} | ||
// Deletes a book from a shelf. | ||
rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {} | ||
} | ||
|
||
// A shelf resource. | ||
message Shelf { | ||
// A unique shelf id. | ||
int64 id = 1; | ||
// A theme of the shelf (fiction, poetry, etc). | ||
string theme = 2; | ||
} | ||
|
||
// A book resource. | ||
message Book { | ||
// A unique book id. | ||
int64 id = 1; | ||
// An author of the book. | ||
string author = 2; | ||
// A book title. | ||
string title = 3; | ||
} | ||
|
||
// Response to ListShelves call. | ||
message ListShelvesResponse { | ||
// Shelves in the bookstore. | ||
repeated Shelf shelves = 1; | ||
} | ||
|
||
// Request message for CreateShelf method. | ||
message CreateShelfRequest { | ||
// The shelf resource to create. | ||
Shelf shelf = 1; | ||
} | ||
|
||
// Request message for GetShelf method. | ||
message GetShelfRequest { | ||
// The ID of the shelf resource to retrieve. | ||
int64 shelf = 1; | ||
} | ||
|
||
// Request message for DeleteShelf method. | ||
message DeleteShelfRequest { | ||
// The ID of the shelf to delete. | ||
int64 shelf = 1; | ||
} | ||
|
||
// Request message for ListBooks method. | ||
message ListBooksRequest { | ||
// ID of the shelf which books to list. | ||
int64 shelf = 1; | ||
} | ||
|
||
// Response message to ListBooks method. | ||
message ListBooksResponse { | ||
// The books on the shelf. | ||
repeated Book books = 1; | ||
} | ||
|
||
// Request message for CreateBook method. | ||
message CreateBookRequest { | ||
// The ID of the shelf on which to create a book. | ||
int64 shelf = 1; | ||
// A book resource to create on the shelf. | ||
Book book = 2; | ||
} | ||
|
||
// Request message for GetBook method. | ||
message GetBookRequest { | ||
// The ID of the shelf from which to retrieve a book. | ||
int64 shelf = 1; | ||
// The ID of the book to retrieve. | ||
int64 book = 2; | ||
} | ||
|
||
// Request message for DeleteBook method. | ||
message DeleteBookRequest { | ||
// The ID of the shelf from which to delete a book. | ||
int64 shelf = 1; | ||
// The ID of the book to delete. | ||
int64 book = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
subprojects { | ||
apply plugin: 'java' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
apply plugin: 'application' | ||
|
||
mainClassName = "com.google.endpoints.examples.bookstore.BookstoreClient" | ||
|
||
jar { | ||
manifest { | ||
attributes "Main-Class": "$mainClassName" | ||
} | ||
from { | ||
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':api') | ||
compile 'commons-cli:commons-cli:1.3' | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we not deploying this anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a link to any published docs that should go here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not yet. We will have public doc referring to these samples, which is in-progress. Is this what you are asking for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - after you publish that doc, if you could add a link to the readme, that would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do. should I add a TODO in this README.md? not sure about the best practice