编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

RPC框架探索:tars初体验(rpc 框架)

wxchong 2024-07-08 01:16:31 开源技术 32 ℃ 0 评论

概述

Tars是腾讯开源的一个框架,定位是微服务治理框架,提供了系统性的解决方案。如下:




Tars应该是一款不错的工具,无赖我这里想搞一套可对比的基于java的RPC框架,2天收集了不少资料,但实在是无法走通哪怕一个最小的tars的helloworld。 主要原因:

  1. 热度不够,自身提供的文档系统性不足
  2. 架构上看,其java的实现体系结构基于web,缺乏继续探寻的动力
  3. 其官方对比的文档看,与spring boot对比而言,缺乏优势


步骤

部署环境

Tars提供了一个平台来管理服务的部署。因此开发Tars服务,需要先部署好其管理平台。管理平台的数据基于MySQL存储。这里基于如下:

version: '3'
services:
  db:
    image: mysql:5.7
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/gauss/soft/docker_app/mysql/dat:/var/lib/mysql"
      - "/home/gauss/soft/docker_app/mysql/cnf:/etc/mysql/conf.d/"
    restart: always
    ports:
     - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
    networks:
     - "my-soft-net"

networks:
  my-soft-net:
    external: true


version: '3'
services:
  framework:
    image: tarscloud/framework:stable
    container_name: tars-framework
    ports:
      - "3000:3000"
      - "3001:3001"
    restart: always
    networks:
     my-soft-net:
        ipv4_address: 192.168.0.10
    environment:
      MYSQL_HOST: "mysql_db_1"
      MYSQL_ROOT_PASSWORD: "password"
      MYSQL_USER: "root"
      MYSQL_PORT: 3306
    volumes:
      - /home/gauss/soft/docker_app/tars/framework/data:/data/tars:rw
      - "/etc/localtime:/etc/localtime:ro"
  node:
    image: tarscloud/tars-node:stable
    container_name: tars-node
    restart: always
    networks:
      my-soft-net:
        ipv4_address: 192.168.0.11
    volumes:
      - /home/gauss/soft/docker_app/tars/node/data:/data/:rw
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      INET: eth0
      WEB_HOST: http://192.168.137.100:3000
    ports:
      - "9000-9010:9000-9010"

networks:
  my-soft-net:
    external: true
#    ipam:
#      config:
#      - subnet: 255.255.255.0/16
#        gateway: 192.168.0.1

代码结构如下


pom文件如下:

<?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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>tars-java-web-svr-study</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>tars-java-web-svr-study Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <!-- https://mvnrepository.com/artifact/com.tencent.tars/tars-server -->
    <dependency>
      <groupId>com.tencent.tars</groupId>
      <artifactId>tars-server</artifactId>
      <version>1.7.2</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>tars-java-web-svr-study</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.1</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF8</encoding>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-compiler-javac</artifactId>
            </dependency>
          </dependencies>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.4</version>
        </plugin>

        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- https://mvnrepository.com/artifact/com.tencent.tars/tars-maven-plugin -->
        <plugin>
          <groupId>com.tencent.tars</groupId>
          <artifactId>tars-maven-plugin</artifactId>
          <version>1.7.2</version>
          <configuration>
            <tars2JavaConfig>
              <tarsFiles>
                <tarsFile>${basedir}/src/main/resources/HelloWorld.tars</tarsFile>
              </tarsFiles>
              <tarsFileCharset>UTF-8</tarsFileCharset>
              <servant>true</servant>
              <srcPath>${basedir}/src/main/java</srcPath>
              <charset>UTF-8</charset>
              <packagePrefixName>demo.</packagePrefixName>
            </tars2JavaConfig>
          </configuration>
        </plugin>

      </plugins>
    </pluginManagement>
  </build>
</project>


参考资料


1、Tars、Spring Cloud 、Service Mesh等微服务框架对比

https://cloud.tencent.com/developer/article/1598863?from=information.detail.TARS%E8%85%BE%E8%AE%AF%E4%BA%91%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0

2、https://tarscloud.org/

3、https://tarscloud.org/

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表