5

求教大佬其他语言如何调用 nacos 服务

 1 year ago
source link: https://www.v2ex.com/t/901246
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

求教大佬其他语言如何调用 nacos 服务

  kestrelBright · 2 小时 46 分钟前 · 655 次点击

现在系统是 lnmp 和 golang 的,只是让用 feign 去调服务,没有 ip 和端口,不知道怎么做,求教

13 条回复    2022-12-09 11:46:12 +08:00

xliao      2 小时 43 分钟前

golang 有 sdk 。PHP 也有第三方 sdk 。实在不行可以请求直接 nacos 的 api 封装

ajaxgoldfish      2 小时 39 分钟前

chatGPT 说的:

nacos 是一个用于构建云原生应用的动态服务发现、配置和服务管理平台。它提供了一系列的 RESTful APIs ,可以通过多种语言来调用 nacos 服务。

例如,在 Java 中可以使用以下代码来调用 nacos 服务:

Copy code
// 创建一个 NacosClient 对象
NacosClient nacosClient = new NacosClient("127.0.0.1", 8848);

// 调用 NacosClient 的相关方法来完成对 nacos 服务的操作
String serviceList = nacosClient.getServiceList();
在其他语言中,比如 Python 、Node.js 或者 Go 等,可以使用 HTTP 协议来调用 nacos 服务,代码示例如下:

Copy code
// Python 中的示例代码
import requests

response = requests.get("http://127.0.0.1:8848/nacos/v1/ns/service")
serviceList = response.text

// Node.js 中的示例代码
const request = require('request')

request.get('http://127.0.0.1:8848/nacos/v1/ns/service', (error, response, body) => {
if (!error && response.statusCode === 200) {
const serviceList = body
}
})

// Go 中的示例代码
import "net/http"

response, _ := http.Get("http://127.0.0.1:8848/nacos/v1/ns/service")
serviceList, _ := ioutil.ReadAll(response.Body)
需要注意的是,上面的代码仅作为示例,实际应用中可能需要根据实际情况进行调整。

Try again


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK