※当サイトの記事には、広告・プロモーションが含まれます。

RPC(Remote Procedure Call)とは? gRPCはGoogle製のRPCフレームワーク

前回、JSONのことについて調べていたら、

qiita.com

JSON-RPCなるものの存在を知り、そんじゃ、RPCって何なのさ?ということになりましたので、調べてみました。

2017年11月26日(日)現在、EclipseEclipse NEON)ではgRPCのプロジェクトのインポートでエラーが解消できていません。Eclipseへのインポート部分は読み飛ばしてください。

コマンドでの起動は確認できています。

 

RPC(Remote Procedure Call)とは?

RPC(Remote Procedure Call)って何ぞ~? 

遠隔手続き呼出しremote procedure call、リモートプロシージャコール、略してRPC)とは、プログラムから別のアドレス空間(通常、共有ネットワーク上の別のコンピュータ上)にあるサブルーチン手続きを実行することを可能にする技術。

その際に遠隔相互作用の詳細を明示的にコーディングする必要がない。

つまり、プログラマはローカルなサブルーチン呼び出しと基本的に同じコードをリモート呼び出しについても行う。

遠隔手続き呼出しを行うソフトウェアがオブジェクト指向プログラミングに基づく場合、遠隔手続き呼出しのことを リモート呼び出しremote invocation)あるいは リモートメソッド呼び出し (remote method invocationRMI)と呼ぶこともある(Java RMIなど)。

遠隔手続き呼出しには例えば、ONC RPCDCE/RPCといった互いに非互換な様々な技術が存在する。

遠隔手続き呼出し - Wikipedia

Oracle Databaseで利用されている「PL/SQL(Procedure Language/Structured Query Language)」なんかでもRPCが使われているみたいですね。(「PL/SQL」はSQLを拡張したものらしいです。)

 

JavaなんかでもRPCを利用できるみたいですね。

RPC使わない場合のイメージ図

f:id:ts0818:20171125145731p:plain

RPC使った場合のイメージ図 

f:id:ts0818:20171125145755p:plain

RPCを使うことで別サーバー(別PC)にあるアプリケーションのJavaのコードとかを実行させることができるようです。

ちなみに、ストアド~(ほにゃらら)については、

ストアド・サブプログラム (stored sub program)とは データベースのOracleさんで使われる表現で、ストアドプロシージャとかストアドファンクションのこと。

ストアドプロシージャストアドファンクションは、データベースに対する「あれやれ、これやれ」の命令を1つにまとめて保存したものです。
データベース世界における関数だと思ってください。

戻り値が無いのがストアドプロシージャです。
戻り値が有るのがストアドファンクションになります。

ストアドサブプログラム (stored sub program)とは|「分かりそう」で「分からない」でも「分かった」気になれるIT用語辞典

ということらしいですね。

www.shift-the-oracle.com

⇧  上記サイト様によると、

『ストアド・パッケージはストアドプロシージャとストアドファンクションのライブラリ集である。多くのケースでメンテナンス性もよいパッケージで管理するのが PL/SQL を使うプロジェクトの定石といえる。』

ということらしいです。

「トリガー(データベース・トリガー)」というものも「ストアド・サブプログラム」に含まれるみたいですね。

 

 

gRPCとは?

 Googleにおけるアプリケーション開発では、スケーラブルなマイクロサービス型のアーキテクチャーが基本となっており、サービス間の通信処理を担うコンポーネントとして、Stubbyと呼ばれる独自のRPCライブラリーが利用されてきました。gRPCは、このライブラリーをオープンソースとして再実装したもので、さまざまなプログラミング言語で使用することができます。
 マイクロサービスの呼び出しには、REST APIもよく利用されますが、REST APIが既存のHTTP(S)プロトコルをそのまま利用しているのに対して、gRPCでは、HTTP/2プロトコルをベースとして、マイクロサービスの連携に必要なさまざまな機能が実装されています。

コラム - グーグルのクラウドを支えるテクノロジー | 第24回 マイクロサービス・システムにおけるgRPCの役割(前編)|CTC教育サービス 研修/トレーニング

ということで、Googleが発祥らしいですね。 

grpc.io

による説明では、 

gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services. 

RPCのフレームワークで、どんな環境でも動くし、オープンソースでもあるそうです。

f:id:ts0818:20171125151025j:plain

⇧  異なるサーバーサイド(上記の例ではJavaRuby間による)でのデータの受け渡しとかいけるみたいですね。

 

gRPCを利用したサービスを手軽に作れる「lile」というライブラリもあるみたいですが、  

mattn.kaoriya.net

こちらのサイト様を参考に一からトライしてみたいと思います。 

qiita.com

 

gRPCを利用してみる、Java

公式サイトのJavaでのチュートリアルのページにアクセスします。

https://grpc.io/docs/quickstart/java.html

f:id:ts0818:20171125162339j:plain

 

JDK version 7 かそれ以上が必要ということみたいですね。「https://github.com/grpc/grpc-java」にgRPCのexampleのプロジェクトがあるみたいですね。

今回は、git cloneでgRPCのexampleのプロジェクトをローカルに持ってきたいと思います。git系のコマンドを利用する場合は、gitクライアントがパソコンにインストールされている必要があります。Windowsの場合は、「Git for Windows」をインストールする感じで大丈夫かと思われます。

gitが利用できるシェル(コマンドが入力できるもの)を起動します。(自分はMsys2のGitのbashを利用しています。)

適当なフォルダに移動しておいて、

cd /C:/Eclipse4.6/pleiades/workspace

git cloneでgRPCのexampleプロジェクトをローカルに持ってきます。

git clone -b v1.7.0 https://github.com/grpc/grpc-java

f:id:ts0818:20171125181653j:plain

f:id:ts0818:20171125181941j:plain

「grpc-java」というフォルダができてます。

f:id:ts0818:20171125182234j:plain

作成されたフォルダに移動し、 

cd grpc-java/examples

コンパイルを行います。 

./gradlew installDist

f:id:ts0818:20171125182458j:plain

「BUILD SUCCESSFUL」となればOK。

f:id:ts0818:20171125182724j:plain

サーバー(gRPC Server)起動します。(C++ Serviceのほうかと思われ。)

./build/install/examples/bin/hello-world-server

f:id:ts0818:20171125183417j:plain

別のシェルを起動して、クライアント(gRPC Client)を起動します。(Java Clientのほうかと思われ。)

f:id:ts0818:20171125184246j:plain

文字化けは自分の使っているシェルの問題ですが、 gRPCのサービスが実行できたということみたいです。

 

EclipseにgRPCプロジェクトをインポート

ファイルを編集していくようですが、せっかくなんでEclipseで開いてみます。「ファイル(F)」>「インポート(I)...」を選択。

f:id:ts0818:20171125193954j:plain

Maven」>「既存 Maven プロジェクト」を選択し、「次へ(N)」をクリック。(gRPCのexampleプロジェクトにpom.xmlファイルがあったので。)

f:id:ts0818:20171125194147j:plain

「ルート・ディレクトリー(R):」に、gRPCのexampleプロジェクトがある場所を指定し、「ワーキング・セットへプロジェクトを追加」する場合は、チェックをつけ適当な名前を決めます。「完了(F)」をクリック。

f:id:ts0818:20171125194358j:plain

無事に....むっちゃエラー出てますね。

f:id:ts0818:20171125194645j:plain

GitHubで紹介されてる説明だと、

github.com

Download the JARs. Or for Maven with non-Android, add to your pom.xml:

<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-netty</artifactId>
  <version>1.7.0</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-protobuf</artifactId>
  <version>1.7.0</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-stub</artifactId>
  <version>1.7.0</version>
</dependency>

って書いてあるんで、pom.xmlを使っていく場合は、

pom.xmlに依存関係を追記すればOKってことですかね。pom.xmlを開きます。

f:id:ts0818:20171125194935j:plain

pom.xmlを編集...って既にpom.xmlに依存関係が追加されてました... 

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.grpc</groupId>
  <artifactId>examples</artifactId>
  <packaging>jar</packaging>
  <!-- Feel free to delete the comment at the end of these lines. It is just
       for safely updating the version in our release process. -->
  <version>1.7.0</version><!-- CURRENT_GRPC_VERSION -->
  <name>examples</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <grpc.version>1.7.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
  </properties>
  <dependencies>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-testing</artifactId>
      <version>${grpc.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.api.grpc</groupId>
      <artifactId>proto-google-common-protos</artifactId>
      <version>0.1.9</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>1.9.5</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.5.0.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.4.0:exe:${os.detected.classifier}</protocArtifact>
          <pluginId>grpc-java</pluginId>
          <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>compile-custom</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforce</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireUpperBoundDeps/>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

嫌な予感がしまくまりですね。素敵な笑顔の方が、「os-maven-plugin」のissuesを記載してくれてるっぽいです。

github.com

どうやら、Eclipseを使ってる場合は、pom.xmlに「os-maven-plugin」って追加してても駄目で、直接「os-maven-plugin」のjarを配置しましょうってことみたいですね。

Issues with Eclipse m2e or other IDEs

If you are using IntelliJ IDEA, you should not have any problem.

If you are using Eclipse, you need to install an additional Eclipse plugin because m2e does not evaluate the extension specified in a pom.xmlDownload os-maven-plugin-1.5.0.Final.jar and put it into the <ECLIPSE_HOME>/plugins directory.

(As you might have noticed, os-maven-plugin is a Maven extension, a Maven plugin, and an Eclipse plugin.)

If you are using other IDEs such as NetBeans, you need to set the system properties os-maven-plugin sets manually when your IDE is launched. You usually use JVM's -D flags like the following:

-Dos.detected.name=linux -Dos.detected.arch=x86_64 -Dos.detected.classifier=linux-x86_64

サイトの説明の中のリンクをクリックすると、

 Download os-maven-plugin-1.5.0.Final.jar 

jarファイルがダウンロードされるので、

f:id:ts0818:20171125204352j:plain

Eclipseがインストールされているフォルダの中の「plugins」フォルダに配置します。(自分の場合は、Cドライブ直下にEclipseを「Eclipse4.6」というフォルダ名でインストールしたので、『C:¥Eclipse4.6¥pleiades¥eclipse¥plugins』フォルダに配置してます。)

f:id:ts0818:20171125204836p:plain

配置できました。 

f:id:ts0818:20171125205845j:plain

Eclipseを再起動して、これで動き...ません。なんか、.protoファイルが上手く機能していてないのか分からんのですが、ところどころでJavaのクラスファイルが生成されてないっぽいですね。

f:id:ts0818:20171126145152j:plain

プロジェクトを選択した状態で右クリックし、「実行(R)」>「5 Maven Clean」を実行すると、

f:id:ts0818:20171126145713j:plain

BUILD SUCCESSってなりました。 

f:id:ts0818:20171126145947j:plain

プロジェクトを選択した状態で右クリックし、「実行(R)」>「7 Maven install」を実行すると、

f:id:ts0818:20171126151223j:plain

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: windows
[INFO] os.detected.arch: x86_64
[INFO] os.detected.version: 10.0
[INFO] os.detected.version.major: 10
[INFO] os.detected.version.minor: 0
[INFO] os.detected.classifier: windows-x86_64
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building examples 1.7.0
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repo.maven.apache.org/maven2/io/grpc/grpc-core/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/io/grpc/grpc-core/maven-metadata.xml (2 KB at 1.1 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/io/netty/netty-codec-http2/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/io/netty/netty-codec-http2/maven-metadata.xml (2 KB at 4.6 KB/sec)
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ examples ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.3/commons-lang-2.3.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.3/commons-lang-2.3.pom (11 KB at 13.9 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-api/1.4.1/enforcer-api-1.4.1.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-api/1.4.1/enforcer-api-1.4.1.pom (3 KB at 9.2 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-rules/1.4.1/enforcer-rules-1.4.1.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-rules/1.4.1/enforcer-rules-1.4.1.pom (4 KB at 12.5 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18n/1.0-beta-6/plexus-i18n-1.0-beta-6.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18n/1.0-beta-6/plexus-i18n-1.0-beta-6.pom (771 B at 2.6 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.4/plexus-components-1.1.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.4/plexus-components-1.1.4.pom (3 KB at 6.7 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing-harness/1.3/maven-plugin-testing-harness-1.3.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing-harness/1.3/maven-plugin-testing-harness-1.3.pom (4 KB at 11.8 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing/1.3/maven-plugin-testing-1.3.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing/1.3/maven-plugin-testing-1.3.pom (10 KB at 29.6 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.pom (4 KB at 10.4 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.20/plexus-components-1.1.20.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.20/plexus-components-1.1.20.pom (3 KB at 10.2 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.0.4/plexus-io-2.0.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.0.4/plexus-io-2.0.4.pom (2 KB at 5.6 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.3/commons-lang-2.3.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.3/commons-lang-2.3.jar (240 KB at 262.6 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-api/1.4.1/enforcer-api-1.4.1.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-api/1.4.1/enforcer-api-1.4.1.jar (12 KB at 37.7 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-rules/1.4.1/enforcer-rules-1.4.1.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer-rules/1.4.1/enforcer-rules-1.4.1.jar (97 KB at 279.9 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18n/1.0-beta-6/plexus-i18n-1.0-beta-6.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18n/1.0-beta-6/plexus-i18n-1.0-beta-6.jar (12 KB at 41.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing-harness/1.3/maven-plugin-testing-harness-1.3.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-testing/maven-plugin-testing-harness/1.3/maven-plugin-testing-harness-1.3.jar (35 KB at 116.9 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.2/plexus-archiver-2.2.jar (181 KB at 412.4 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.0.4/plexus-io-2.0.4.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.0.4/plexus-io-2.0.4.jar (57 KB at 178.4 KB/sec)
[INFO] artifact io.grpc:grpc-core: checking for updates from central
[INFO] artifact io.netty:netty-codec-http2: checking for updates from central
[INFO] 
[INFO] --- protobuf-maven-plugin:0.5.0:compile (default) @ examples ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.4.0/protoc-3.4.0-windows-x86_64.exe
[INFO] Downloaded: https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.4.0/protoc-3.4.0-windows-x86_64.exe (5564 KB at 2789.0 KB/sec)
[INFO] Compiling 3 proto file(s) to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\generated-sources\protobuf\java
[INFO] 
[INFO] --- protobuf-maven-plugin:0.5.0:compile-custom (default) @ examples ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-java/1.7.0/protoc-gen-grpc-java-1.7.0.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-java/1.7.0/protoc-gen-grpc-java-1.7.0.pom (3 KB at 6.6 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-java/1.7.0/protoc-gen-grpc-java-1.7.0-windows-x86_64.exe
[INFO] Downloaded: https://repo.maven.apache.org/maven2/io/grpc/protoc-gen-grpc-java/1.7.0/protoc-gen-grpc-java-1.7.0-windows-x86_64.exe (1932 KB at 2065.8 KB/sec)
[INFO] Compiling 3 proto file(s) to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\generated-sources\protobuf\grpc-java
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ examples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ examples ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ examples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ examples ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\test-classes
[WARNING] /C:/Eclipse4.6/pleiades/workspace/grpc-java/examples/src/test/java/io/grpc/examples/header/HeaderServerInterceptorTest.java: C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\src\test\java\io\grpc\examples\header\HeaderServerInterceptorTest.javaの操作は、未チェックまたは安全ではありません。
[WARNING] /C:/Eclipse4.6/pleiades/workspace/grpc-java/examples/src/test/java/io/grpc/examples/header/HeaderServerInterceptorTest.java: 詳細は、-Xlint:uncheckedオプションを指定して再コンパイルしてください。
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ examples ---
[INFO] Surefire report directory: C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\surefire-reports
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 8.8 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 8.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 121.0 KB/sec)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running io.grpc.examples.header.HeaderClientInterceptorTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.541 sec
Running io.grpc.examples.header.HeaderServerInterceptorTest
���: header received from client:Metadata(grpc-accept-encoding=gzip) [�� 11 26 15:10:02 JST 2017]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 sec
Running io.grpc.examples.helloworld.HelloWorldClientTest
���: Will try to greet test name ... [�� 11 26 15:10:02 JST 2017]
�x��: RPC failed: Status{code=UNIMPLEMENTED, description=Method helloworld.Greeter/SayHello is unimplemented, cause=null} [�� 11 26 15:10:02 JST 2017]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec
Running io.grpc.examples.helloworld.HelloWorldServerTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running io.grpc.examples.routeguide.RouteGuideClientTest
���: *** RecordRoute [�� 11 26 15:10:02 JST 2017]
�x��: RecordRoute Failed: Status{code=INVALID_ARGUMENT, description=null, cause=null} [�� 11 26 15:10:02 JST 2017]
���: Visiting point 0, 0 [�� 11 26 15:10:02 JST 2017]
���: *** RouteChat [�� 11 26 15:10:02 JST 2017]
���: Sending message "First message" at 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Got message "First message" at 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Second message" at 0, 1 [�� 11 26 15:10:02 JST 2017]
���: Got message "Second message" at 0, 1 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Third message" at 1, 0 [�� 11 26 15:10:02 JST 2017]
���: Got message "Third message" at 1, 0 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Fourth message" at 1, 1 [�� 11 26 15:10:02 JST 2017]
���: Got message "Fourth message" at 1, 1 [�� 11 26 15:10:02 JST 2017]
���: Finished RouteChat [�� 11 26 15:10:02 JST 2017]
���: *** RouteChat [�� 11 26 15:10:02 JST 2017]
���: Sending message "First message" at 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Second message" at 0, 1 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Third message" at 1, 0 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Fourth message" at 1, 1 [�� 11 26 15:10:02 JST 2017]
���: Got message "dummy msg1" at 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Got message "dummy msg2" at 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Finished RouteChat [�� 11 26 15:10:02 JST 2017]
���: *** GetFeature: lat=-1 lon=-1 [�� 11 26 15:10:02 JST 2017]
���: Found feature called "dummyFeature" at -0, -0 [�� 11 26 15:10:02 JST 2017]
���: *** RouteChat [�� 11 26 15:10:02 JST 2017]
���: Sending message "First message" at 0, 0 [�� 11 26 15:10:02 JST 2017]
�x��: RouteChat Failed: Status{code=PERMISSION_DENIED, description=null, cause=null} [�� 11 26 15:10:02 JST 2017]
���: Sending message "Second message" at 0, 1 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Third message" at 1, 0 [�� 11 26 15:10:02 JST 2017]
���: Sending message "Fourth message" at 1, 1 [�� 11 26 15:10:02 JST 2017]
���: *** ListFeatures: lowLat=1 lowLon=2 hiLat=3 hiLon=4 [�� 11 26 15:10:02 JST 2017]
���: Result #1: name: "feature 1"
 [�� 11 26 15:10:02 JST 2017]
���: Result #2: name: "feature 2"
 [�� 11 26 15:10:02 JST 2017]
���: *** RecordRoute [�� 11 26 15:10:02 JST 2017]
���: Visiting point 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Visiting point 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Visiting point 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Visiting point 0, 0 [�� 11 26 15:10:02 JST 2017]
���: Finished trip with 7 points. Passed 8 features. Travelled 9 meters. It took 10 seconds. [�� 11 26 15:10:02 JST 2017]
���: Finished RecordRoute [�� 11 26 15:10:02 JST 2017]
���: *** ListFeatures: lowLat=1 lowLon=2 hiLat=3 hiLon=4 [�� 11 26 15:10:02 JST 2017]
���: Result #1: name: "feature 1"
 [�� 11 26 15:10:02 JST 2017]
�x��: RPC failed: Status{code=INVALID_ARGUMENT, description=null, cause=null} [�� 11 26 15:10:02 JST 2017]
���: *** GetFeature: lat=-1 lon=-1 [�� 11 26 15:10:02 JST 2017]
�x��: RPC failed: Status{code=DATA_LOSS, description=null, cause=null} [�� 11 26 15:10:02 JST 2017]
Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.145 sec
Running io.grpc.examples.routeguide.RouteGuideServerTest
���: Server started, listening on 0 [�� 11 26 15:10:02 JST 2017]
���: Server started, listening on 0 [�� 11 26 15:10:02 JST 2017]
���: Server started, listening on 0 [�� 11 26 15:10:03 JST 2017]
���: Server started, listening on 0 [�� 11 26 15:10:03 JST 2017]
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 sec
*** shutting down gRPC server since JVM is shutting down
*** shutting down gRPC server since JVM is shutting down
*** shutting down gRPC server since JVM is shutting down
*** shutting down gRPC server since JVM is shutting down
*** server shut down
*** server shut down
*** server shut down
*** server shut down

Results :

Tests run: 17, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ examples ---
[INFO] Building jar: C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\examples-1.7.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ examples ---
[INFO] Installing C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\examples-1.7.0.jar to C:\Users\Toshinobu\.m2\repository\io\grpc\examples\1.7.0\examples-1.7.0.jar
[INFO] Installing C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\pom.xml to C:\Users\Toshinobu\.m2\repository\io\grpc\examples\1.7.0\examples-1.7.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.000 s
[INFO] Finished at: 2017-11-26T15:10:03+09:00
[INFO] Final Memory: 24M/186M
[INFO] ------------------------------------------------------------------------

一応、BUILD SUCCESSってなって、pom.xmlのエラーは消えたんですが、残りのエラーは変わらず。

f:id:ts0818:20171126152252j:plain

気になったのは、コンソールの内容で

[WARNING] /C:/Eclipse4.6/pleiades/workspace/grpc-java/examples/src/test/java/io/grpc/examples/header/HeaderServerInterceptorTest.java: C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\src\test\java\io\grpc\examples\header\HeaderServerInterceptorTest.javaの操作は、未チェックまたは安全ではありません。 
[WARNING] /C:/Eclipse4.6/pleiades/workspace/grpc-java/examples/src/test/java/io/grpc/examples/header/HeaderServerInterceptorTest.java: 詳細は、-Xlint:uncheckedオプションを指定して再コンパイルしてください。    
    

って部分ですかね。「-Xlint:uncheckedオプションを指定して再コンパイル」ってのが何をすれば良いのかがよく分からない...。

qiita.com

⇧  上記サイト様に掲載されていました。

 

Spring Tool Suite(Eclipse)の場合の方法ですが、Eclipseの場合でもいけると思われますが、

qiita.com

⇧  上記サイト様に掲載されてました。

 

というわけで、Eclipseで「ウィンドウ(W)」>「設定(P)」を選択。

f:id:ts0818:20171126160800j:plain

Java」>「コンパイラー」の「メソッド・パラメーターの情報を保管(S)(リフレクション経由で使用可能)」にチェックを入れ、「OK」。

f:id:ts0818:20171126161108j:plain

「-Xlint:uncheckedオプションを指定して再コンパイル」する必要があるようなので、「いいえ(N)」を選択。

f:id:ts0818:20171126161254j:plain

では、プロジェクトを選択した状態で右クリックし、「実行(R)」>「実行の構成(N)...」を選択。

f:id:ts0818:20171126162711j:plain

「パラメーター名」のエリアの横の「追加(A)...」をクリックし、

f:id:ts0818:20171126162922j:plain

 「名前:」に「Xlint」、「値:」に「unchecked」を入力し、「OK」。

f:id:ts0818:20171126163029j:plain

パラメーターが追加されていることを確認し、「ゴール(G):」に「compile」と入力し(「プロファイル(P):」はpom.xmlに該当項目が見当たらなかったので空白に。)、「ユーザー設定:」に「プロジェクトのpom.xml」を指定。

「適応(Y)」したら「閉じる」。

f:id:ts0818:20171126163648j:plain

プロジェクトを選択した状態で右クリックし、「実行(R)」>「9 Maven ビルド」を選択。

f:id:ts0818:20171126164026j:plain

「examples: compile」を選択し、「OK」。

f:id:ts0818:20171126164121j:plain

 

[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Expected root element 'settings' but found 'project' (position: START_TAG seen ...en.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">... @2:99)  @ C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\pom.xml, line 2, column 99
[WARNING] 
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: windows
[INFO] os.detected.arch: x86_64
[INFO] os.detected.version: 10.0
[INFO] os.detected.version.major: 10
[INFO] os.detected.version.minor: 0
[INFO] os.detected.classifier: windows-x86_64
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building examples 1.7.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ examples ---
[INFO] 
[INFO] --- protobuf-maven-plugin:0.5.0:compile (default) @ examples ---
[INFO] Compiling 3 proto file(s) to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\generated-sources\protobuf\java
[INFO] 
[INFO] --- protobuf-maven-plugin:0.5.0:compile-custom (default) @ examples ---
[INFO] Compiling 3 proto file(s) to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\generated-sources\protobuf\grpc-java
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ examples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ examples ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to C:\Eclipse4.6\pleiades\workspace\grpc-java\examples\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.950 s
[INFO] Finished at: 2017-11-26T16:24:54+09:00
[INFO] Final Memory: 21M/275M
[INFO] ------------------------------------------------------------------------

BUILD SUCCSESSってなるもWARNINGが出てるのが気になりますね。

 

いろいろ、インストールできたということで、プロジェクトを更新してみます。プロジェクトを選択した状態で右クリックし、「Maven(M)」>「プロジェクトの更新(U)...」を選択。

f:id:ts0818:20171126152426j:plain

 「OK」をクリック。

f:id:ts0818:20171126152900j:plain

エラーが減るも、やはり、Javaのクラスが生成されてないっぽいですね。

f:id:ts0818:20171126152938j:plain

 

 

で、似たような現象のissueを上げている人がいて、

github.com

質問者の質問に対する答えが結構ひどい。最初は、「os-maven-plugin」 の問題でしょう、みたいなこと言っておいて、最終的に、

It obviously works on the command line, when the entire lifecycle is executed, and all build extensions are properly initialised beforehand. But does not work in Eclipse, which does things in its own peculiar way.

Eclipseは独特な動作をするので、ちょっと私には分かりません的な身もふたもない結論で片づけるという...なんじゃそら~。

 

ちなみに、こちらの方もEclipseの問題じゃないか~的なissueを上げてますが、まだ誰の見解も上がってないようです。

github.com

イケイケなお兄さんも、質問してましたが、

github.com

回答の結論として、

It must be some sort of class loading issue in Eclipse that prevents the correct functioning of the os-maven-plugin and its Eclipse extension. I am really sorry, but I won't be able to help you resolve that (and the root cause does not seem to be related to protobuf-maven-plugin at all). Please raise an issue against os-maven-plugin or Eclipse, or both.

「os-maven-plugin」か、EclipseIDE)特有の問題っちゅう結論で片づけるという、結局解決できてない...。

 

Google Cloud Platformの公式ブログだと、Eclipseで動かしました~って載っていて、

cloudplatform-jp.googleblog.com

ここのGitHubリポジトリのものをEclipseで動かしたってことらしいですね。

github.com

導入の仕方をYou Tubeで紹介しているみたいなんですが、英語での説明であるのと、IDE統合開発環境)として IntelliJ IDEA を使っているという...Eclipseのやり方は?

とりあえず、公式ブログの人の言葉を信じて、プロジェクトをEclipseワークスペースにインポートしてみますか。

 

Google Cloud Platformの公式ブログで紹介されていたgRPCプロジェクトをEclipseインポート

Eclipseで利用したいワークスペースフォルダに新しくgRPCプロジェクト用のフォルダを作成しておいて、

f:id:ts0818:20171126140338j:plain

git cloneする場合は、ディレクトリ(作成したgRPCプロジェクト用のフォルダ)まで移動しておいて、

cd /C:/Eclipse4.6/pleiades/workspace/grpc-java-second

git clone。

git clone https://github.com/saturnism/grpc-java-by-example.git

f:id:ts0818:20171126140607j:plain

GitHubリポジトリから持ってこれてますね。

f:id:ts0818:20171126141108j:plain

そんでは、Eclipseでインポートしてみたいと思います。「ファイル(F)」>「インポート(I)....」を選択。

f:id:ts0818:20171126141809j:plain

Maven」>「既存 Maven プロジェクト」を選択し、「次へ(N)>」。

f:id:ts0818:20171126141824j:plain

むっちゃpom.xmlありますね...「ワーキング・セットへプロジェクトを追加」にチェックを入れ、「完了(F)」。

f:id:ts0818:20171126142020j:plain

怒涛のエラーが出てますが...処理の途中で、 

f:id:ts0818:20171126142731j:plain

ダイアログが出たのですが、そのまま「完了(F)」してしまった。

f:id:ts0818:20171126142814j:plain

処理が継続して、しばらく経つとまたダイアログが出たので、「次へ(N)>」。

f:id:ts0818:20171126143149j:plain

「次へ(N)>」。

f:id:ts0818:20171126143311j:plain

「使用条件の条項に同意します(A)」にチェックし、「完了(F)」。

f:id:ts0818:20171126143341j:plain

処理が継続して、ダイアログが出たら「OK」。

f:id:ts0818:20171126143605j:plain

エラーが止まることを知らない感じになってますが、

f:id:ts0818:20171126144227j:plain

再起動の要請があるので、「はい(Y)」で。

f:id:ts0818:20171126144317j:plain

再起動するも、

f:id:ts0818:20171126144404j:plain

エラーは消えず...。

f:id:ts0818:20171126144712j:plain

 

Google Cloud PlatFormのブログでEclipse導入できました~って言ってるなら、その方法の詳細を掲載してくれないものか...。

EclipseでのgRPCの導入はしばらく見送りになりそうです...。今回も大いに時間を浪費してしまった。