zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    es集群的调优2
    es集群中kibana和es集群的高可用设置
    es集群中参数参数discovery.zen.minimum_master_nodes深度解析
    哔哩哔哩适合后端编程人员的elasticsearch快速实战教程学习总结
    Vue2-基本语句
    SpringBoot-ElasticSearch初使用
    Java-SSO单点登录的3种方式【待完善】
    Java-学习日记(函数式编程与@ControllerAdvice)
    SpringBoot-内置Tomcat启动原理
    Java-学习日记(Atomic,Volatile)
  • 原文地址:https://www.cnblogs.com/rufus-hua/p/4159278.html
Copyright © 2011-2022 走看看