{"id":27603747,"url":"https://github.com/tarscloud/tarsjava","last_synced_at":"2025-04-22T19:19:13.751Z","repository":{"id":33031825,"uuid":"148126270","full_name":"TarsCloud/TarsJava","owner":"TarsCloud","description":"Java language framework rpc source code implementation","archived":false,"fork":false,"pushed_at":"2024-11-01T07:23:11.000Z","size":6094,"stargazers_count":407,"open_issues_count":35,"forks_count":170,"subscribers_count":25,"default_branch":"v1.7.x","last_synced_at":"2025-04-22T19:19:07.687Z","etag":null,"topics":["high-availability","high-performance","microservices","rpc","springboot","tars","tars-foundation"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TarsCloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-10T08:50:36.000Z","updated_at":"2025-03-11T09:49:43.000Z","dependencies_parsed_at":"2024-08-13T11:29:33.735Z","dependency_job_id":null,"html_url":"https://github.com/TarsCloud/TarsJava","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarsCloud%2FTarsJava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarsCloud%2FTarsJava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarsCloud%2FTarsJava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TarsCloud%2FTarsJava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TarsCloud","download_url":"https://codeload.github.com/TarsCloud/TarsJava/tar.gz/refs/heads/v1.7.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306604,"owners_count":21408927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["high-availability","high-performance","microservices","rpc","springboot","tars","tars-foundation"],"created_at":"2025-04-22T19:19:13.037Z","updated_at":"2025-04-22T19:19:13.739Z","avatar_url":"https://github.com/TarsCloud.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\nTars Java - An RPC library and framework\n========================================\n[![Latest release](https://img.shields.io/github/v/release/tarsCloud/TarsJava)](https://github.com/TarsCloud/TarsJava/releases/latest)\n\n\nThis project is the source code of the Tars RPC framework Java language.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eHomepage:\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://tarscloud.org\"\u003etarscloud.org\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003cb\u003e中文版:\u003c/b\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ca href=\"README.zh.md\"\u003e点我查看中文版\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n\n###  Environmental dependence\n- JDK1.8 or above\n- Maven 3.5 or above\n\n###\n\n\n\n\n## TarsFramework deployment by Docker\n\nThis guide uses Docker to complete the deployment of Tars.[Macos、 Linux]\n\n**2. Start TarsFramework in Docker**\n\n```bash\ndocker pull tarscloud/framework:latest\ndocker pull tarscloud/tars-node:latest\ndocker pull   mysql:5.6\ndocker network create -d bridge --subnet=172.25.0.0/16 --gateway=172.25.0.1 tars\ndocker run -d \\\n--net=tars \\\n-e MYSQL_ROOT_PASSWORD=\"root@appinside\" \\\n--ip=\"172.25.0.2\" \\\n--name=tars-mysql \\\nmysql:5.6\nsleep 30s\ndocker run -d \\\n--net=tars \\\n-e MYSQL_HOST=172.25.0.2 \\\n-e MYSQL_ROOT_PASSWORD='root@appinside' \\\n-eREBUILD=false  -eSLAVE=false \\\n-e INET=eth0 \\\n--ip=\"172.25.0.4\" \\\n-p 3000-3001:3000-3001 \\\ntarscloud/framework\nsleep 60s\ndocker run -d --net=tars --ip=\"172.25.0.3\"  -eWEB_HOST=http://172.25.0.4:3000        tarscloud/tars-node\n```\n\n**Note: - P 18600-18700:18600-18700 parameter opens 18600-18700 port for application. You can add more ports if necessary**\n\n\n# Quick Start To TarsServer\n\nThis guide gives you a quick introduction to Tars in Java through simple server\n\n#### Project structure\n\n```text\n├── pom.xml\n└── src\n   └── main\n       ├── java\n       │   └── tars\n       │       └── testapp\n       │          ├── HelloServant.java\n       │          ├── QuickStartApplication.java\n       │          └── impl\n       │                └── HelloServantImpl.java\n       └── resources\n           └── hello.tars\n       \n```\n\n\n\n#### Dependency configuration\n\nThe following configuration needs to be added in pom.xml:\n\n**Spring boot and Tars framework dependency**\n\n```xml\n    \u003cproperties\u003e\n        \u003cspring-boot.version\u003e2.0.3.RELEASE\u003c/spring-boot.version\u003e\n    \u003c/properties\u003e\n\n    \u003cdependencyManagement\u003e\n        \u003cdependencies\u003e\n            \u003cdependency\u003e\n                \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n                \u003cartifactId\u003espring-boot-dependencies\u003c/artifactId\u003e\n                \u003cversion\u003e${spring-boot.version}\u003c/version\u003e\n                \u003ctype\u003epom\u003c/type\u003e\n                \u003cscope\u003eimport\u003c/scope\u003e\n            \u003c/dependency\u003e\n        \u003c/dependencies\u003e\n    \u003c/dependencyManagement\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.tencent.tars\u003c/groupId\u003e\n            \u003cartifactId\u003etars-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e1.7.4\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n```\n\n**Plugin dependency**\n\n```xml\n\u003c!--tars2java plugin--\u003e\n\u003cplugin\u003e\n\t\u003cgroupId\u003ecom.tencent.tars\u003c/groupId\u003e\n\t\u003cartifactId\u003etars-maven-plugin\u003c/artifactId\u003e\n\t\u003cversion\u003e1.7.0\u003c/version\u003e\n\t\u003cconfiguration\u003e\n\t\t\u003ctars2JavaConfig\u003e\n\t\t\t\u003c!-- tars file location --\u003e\n\t\t\t\u003ctarsFiles\u003e\n\t\t\t\t\u003ctarsFile\u003e${basedir}/src/main/resources/hello.tars\u003c/tarsFile\u003e\n\t\t\t\u003c/tarsFiles\u003e\n\t\t\t\u003c!-- Source file encoding --\u003e\n\t\t\t\u003ctarsFileCharset\u003eUTF-8\u003c/tarsFileCharset\u003e\n\t\t\t\u003c!-- Generate server code --\u003e\n\t\t\t\u003cservant\u003etrue\u003c/servant\u003e\n\t\t\t\u003c!-- Generated source code encoding --\u003e\n\t\t\t\u003ccharset\u003eUTF-8\u003c/charset\u003e\n\t\t\t\u003c!-- Generated source code directory --\u003e\n\t\t\t\u003csrcPath\u003e${basedir}/src/main/java\u003c/srcPath\u003e\n\t\t\t\u003c!-- Generated source code package prefix --\u003e\n\t\t\t\u003cpackagePrefixName\u003ecom.qq.tars.quickstart.server.\u003c/packagePrefixName\u003e\n\t\t\u003c/tars2JavaConfig\u003e\n\t\u003c/configuration\u003e\n\u003c/plugin\u003e\n\u003c!--package plugin--\u003e\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-jar-plugin\u003c/artifactId\u003e\n     \u003cversion\u003e2.6\u003c/version\u003e\n     \u003cconfiguration\u003e\n         \u003carchive\u003e\n             \u003cmanifestEntries\u003e\n                 \u003cClass-Path\u003econf/\u003c/Class-Path\u003e\n             \u003c/manifestEntries\u003e\n          \u003c/archive\u003e\n     \u003c/configuration\u003e\n\u003c/plugin\u003e\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n    \u003cconfiguration\u003e\n        \u003c!--set mainclass--\u003e\n        \u003cmainClass\u003ecom.qq.tars.quickstart.server.QuickStartApplication\u003c/mainClass\u003e\n    \u003c/configuration\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003erepackage\u003c/goal\u003e\n             \u003c/goals\u003e\n     \u003c/executions\u003e\n\u003c/plugin\u003e\n```\n\n\n\n#### Service development\n\n##### Tars interface file definition\n\nTars has its own interface file format. First, we need to define the Tars interface file. Create a new hello.tars file in the resources directory with the following content:\n\n```text\nmodule TestApp\n{\n\tinterface Hello\n\t{\n\t    string hello(int no, string name);\n\t};\n};\n```\n\n##### Interface file compilation\n\nThen we need to convert the Tars interface file to the server interface code using the tars-maven-plugin. In the project root directory, execute `mvn tars: tars2java` to get HelloServant.java, the content is as follows:\n\n```java\n@Servant\npublic interface HelloServant {\n\n\tpublic String hello(int no, String name);\n}\n```\n\n##### Interface implementation\n\nNext we need to implement the generated server interface. Create a new HelloServantImpl.java file, implement the HelloServant.java interface, and expose the service through the @TarsServant annotation, where 'HelloObj' is the servant name, corresponding to the name in the web management platform.\n\n```java\n@TarsServant(\"HelloObj\")\npublic class HelloServantImpl implements HelloServant {\n\n    @Override\n    public String hello(int no, String name) {\n        return String.format(\"hello no=%s, name=%s, time=%s\", no, name, System.currentTimeMillis());\n    }\n}\n```\n\n##### Tars service enabling\n\nFinally, add @EnableTarsServer annotation in the spring boot startup class QuickStartApplication to enable Tars service:\n\n```java\n@SpringBootApplication\n@EnableTarsServer\npublic class QuickStartApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(QuickStartApplication.class, args);\n    }\n}\n```\n\n\n\n\n| Directory               | Features               |\n| ------------------ | ---------------- |\n| net                | Source code implementation of Java language net framework         |\n| core               | Source code implementation of Java language rpc framework         |\n| tools              | Source code implementation of framework tools, maven plug-ins, etc |\n| examples           | Sample code for the Java language framework          |\n| distributedContext | Source code implementation of Java language framework's distributed context       |\n| protobuf           | Source code implementation of pb protocol support        |\n| spring             | Source code implementation of spring framework support      |\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarscloud%2Ftarsjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarscloud%2Ftarsjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarscloud%2Ftarsjava/lists"}