java搭建finagle(1)

1、新建maven项目

2、pom文件添加依赖

添加3个主要依赖
<
dependency> <groupId>com.twitter</groupId> <artifactId>scrooge-core_2.10</artifactId> <version>${scrooge.version}</version> </dependency> <dependency> <groupId>com.twitter</groupId> <artifactId>finagle-thrift_2.10</artifactId> <version>${finagle.version}</version> </dependency> <dependency> <groupId>com.twitter</groupId> <artifactId>finagle-serversets_2.10</artifactId> <version>${finagle.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> </exclusion> </exclusions> </dependency>
ps:注用的
finagle.version 6.20.0
然后添加依赖源 注:这个网址被墙 请在 maven 配置代理。
<repositories>
<repository>
<id>twitter-twttr</id>
<url>http://maven.twttr.com/</url>
</repository>
</repositories>
中央仓库已经包含了 不用指定这个仓库

3、然后配置 一个插件 根据thrift文件生成java文件(这个插件很重要)

<build><plugins> 下面配置
  <plugin>
      <groupId>com.twitter</groupId>
      <artifactId>scrooge-maven-plugin</artifactId>
      <version>${scrooge.version}</version>
      <configuration>
          <thriftNamespaceMappings>
              <thriftNamespaceMapping>
                  <from>com.twitter.demo</from>
                  <to>xxxxxxxx</to>
              </thriftNamespaceMapping>
          </thriftNamespaceMappings>
          <language>java</language> <!-- default is scala -->
          <thriftOpts>
              <!-- add other Scrooge command line options using thriftOpts -->
              <thriftOpt>--finagle</thriftOpt>
              <!--<thriftOpt>\-\-ostrich</thriftOpt>-->
          </thriftOpts>
          <!-- tell scrooge to extract thrifts from these artifacts -->
          <dependencyIncludes>
              <include>event-logger-thrift</include>
          </dependencyIncludes>
      </configuration>
      <executions>
          <execution>
              <id>thrift-sources</id>
              <phase>generate-sources</phase>
              <goals>
                  <goal>compile</goal>
              </goals>
          </execution>
          <execution>
              <id>thrift-test-sources</id>
              <phase>generate-test-sources</phase>
              <goals>
                  <goal>testCompile</goal>
              </goals>
          </execution>
      </executions>
  </plugin>
注:红色部分 to 需要自己填写 所要的自己想要的包名,也就是生成文件的包名

4、在项目文件src/main 下新建 thrift 文件夹(和java文件夹同级)

新建thrift文件..写入thrift。。不罗嗦。。然后 编译 会自动生成 thrift对应的java文件。

5、根据java文件继承 xxx.ServerIface 实现定义的接口

下篇文章 在这 http://www.cnblogs.com/rufus-hua/p/4969863.html

posted @ 2014-12-12 11:06  沐松  阅读(3368)  评论(2编辑  收藏  举报