{"id":15777422,"url":"https://github.com/v5tech/nats-example","last_synced_at":"2025-03-31T15:38:44.701Z","repository":{"id":149461750,"uuid":"116807091","full_name":"v5tech/nats-example","owner":"v5tech","description":"Demo project for Spring Boot NATS","archived":false,"fork":false,"pushed_at":"2018-01-11T04:10:57.000Z","size":306,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T18:02:43.273Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/v5tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-01-09T11:24:49.000Z","updated_at":"2018-01-10T02:10:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa1cd8ed-1616-42d9-83ab-c226ef8454ce","html_url":"https://github.com/v5tech/nats-example","commit_stats":null,"previous_names":["v5tech/nats-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fnats-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fnats-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fnats-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fnats-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/v5tech","download_url":"https://codeload.github.com/v5tech/nats-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246490871,"owners_count":20786074,"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":[],"created_at":"2024-10-04T18:00:32.833Z","updated_at":"2025-03-31T15:38:44.669Z","avatar_url":"https://github.com/v5tech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nats-example\n\n## 示例演示\n\n集群环境搭建\n\n```bash\ngnatsd -a 10.61.8.7 -p 4222 -m 8222 -cluster nats://10.61.8.7:5222 -routes nats://10.61.8.10:5222,nats://10.61.8.18:5222 -DV\n\ngnatsd -a 10.61.8.10 -p 4222 -m 8222 -cluster nats://10.61.8.10:5222 -routes nats://10.61.8.7:5222,nats://10.61.8.18:5222 -DV\n\ngnatsd -a 10.61.8.18 -p 4222 -m 8222 -cluster nats://10.61.8.18:5222 -routes nats://10.61.8.7:5222,nats://10.61.8.10:5222 -DV\n```\n\n访问监控观察集群状态\n\nhttp://10.61.8.7:8222\n\nhttp://10.61.8.10:8222\n\nhttp://10.61.8.18:8222\n\n![](Screenshots/20180111103332.png)\n![](Screenshots/20180111103301.png)\n![](Screenshots/20180111103310.png)\n![](Screenshots/20180111103321.png)\n\n\n## Linux远程部署\n\n```bash\nmvn package\n```\n\nMAVEN本地打包远程部署日志输出\n```bash\n\"C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java\" -Dmaven.multiModuleProjectDirectory=C:\\Users\\Administrator\\Desktop\\nats-example\\spring-boot-nats-example -Dmaven.home=D:\\maven -Dclassworlds.conf=D:\\maven\\bin\\m2.conf -Didea.launcher.port=61243 \"-Didea.launcher.bin.path=C:\\Program Files\\JetBrains\\IntelliJ IDEA 2017.2.3\\bin\" -Dfile.encoding=UTF-8 -classpath \"D:\\maven\\boot\\plexus-classworlds-2.5.2.jar;C:\\Program Files\\JetBrains\\IntelliJ IDEA 2017.2.3\\lib\\idea_rt.jar\" com.intellij.rt.execution.application.AppMainV2 org.codehaus.classworlds.Launcher -Didea.version=2017.2.6 -s D:\\maven\\conf\\settings.xml package\n[INFO] Scanning for projects...\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] Building spring-boot-nats-example 1.0\n[INFO] ------------------------------------------------------------------------\n[INFO] \n[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ spring-boot-nats-example ---\n[INFO] Using 'UTF-8' encoding to copy filtered resources.\n[INFO] Copying 1 resource\n[INFO] Copying 0 resource\n[INFO] \n[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ spring-boot-nats-example ---\n[INFO] Nothing to compile - all classes are up to date\n[INFO] \n[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ spring-boot-nats-example ---\n[INFO] Using 'UTF-8' encoding to copy filtered resources.\n[INFO] skip non existing resourceDirectory C:\\Users\\Administrator\\Desktop\\nats-example\\spring-boot-nats-example\\src\\test\\resources\n[INFO] \n[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ spring-boot-nats-example ---\n[INFO] No sources to compile\n[INFO] \n[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ spring-boot-nats-example ---\n[INFO] No tests to run.\n[INFO] \n[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ spring-boot-nats-example ---\n[INFO] Building jar: C:\\Users\\Administrator\\Desktop\\nats-example\\spring-boot-nats-example\\target\\spring-boot-nats-example-1.0.jar\n[INFO] \n[INFO] --- spring-boot-maven-plugin:1.5.6.RELEASE:repackage (default) @ spring-boot-nats-example ---\n[INFO] \n[INFO] --- wagon-maven-plugin:1.0:upload-single (upload-deploy) @ spring-boot-nats-example ---\n[INFO] Uploading: C:\\Users\\Administrator\\Desktop\\nats-example\\spring-boot-nats-example\\target\\spring-boot-nats-example-1.0.jar scp://10.61.8.18/opt/spring-boot-nats-example-1.0.jar\n[INFO] \n[INFO] --- wagon-maven-plugin:1.0:sshexec (upload-deploy) @ spring-boot-nats-example ---\n[INFO] sshexec: pkill -f spring-boot-nats-example-1.0.jar\n\n\n[INFO] sshexec: nohup java -jar /opt/spring-boot-nats-example-1.0.jar \u003e /opt/nohup.out 2\u003e\u00261 \u0026\n\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 5.411 s\n[INFO] Finished at: 2018-01-11T12:07:46+08:00\n[INFO] Final Memory: 28M/325M\n[INFO] ------------------------------------------------------------------------\n\nProcess finished with exit code 0\n```\n\n## 程序运行控制台\n\n![](Screenshots/20180111104002.png)\n\n程序运行起来首先订阅了`some.nats.subject`,然后每隔5秒向`some.nats.subject`发布消息。从日志中可以看出`NATS`会尝试自动重连.\n\n## 参考文章\n\nhttps://nats.io/documentation/server/gnatsd-cluster/\n\nhttps://github.com/cloudfoundry-community/java-nats/tree/master/client\n\nhttps://nats.io/documentation/server/gnatsd-cluster/\n\nhttp://gomqtt.taitan.org/user-guide/install/#nats\n\nhttp://www.cnblogs.com/liang1101/category/975332.html\n\nhttp://blog.csdn.net/chszs/article/category/5987039\n\nhttps://github.com/ChinaSilence/spring-boot-starter-nats\n\nhttp://xxgblog.com/2015/10/23/wagon-maven-plugin/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Fnats-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fv5tech%2Fnats-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Fnats-example/lists"}