Skip to content

Commit

Permalink
update new blog
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 14, 2023
1 parent 3b936cb commit 36d3345
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 52 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
- RSS:[RSS Feed](https://raw.githubusercontent.com/superleeyom/blog/master/feed.xml)

## 最近更新
- [Postman如何配置动态端口和IP](https://github.com/superleeyom/blog/issues/56)--2023-12-14
- [2023上海之旅](https://github.com/superleeyom/blog/issues/55)--2023-11-21
- [我的跑步数据流](https://github.com/superleeyom/blog/issues/54)--2023-02-18
- [2022年终总结之我的买房经历](https://github.com/superleeyom/blog/issues/53)--2023-01-08
- [2023年个人周报](https://github.com/superleeyom/blog/issues/52)--2023-01-03
- [解决 IDEA 因为 Clash 代理问题引起的疑难杂症](https://github.com/superleeyom/blog/issues/51)--2022-09-28
## 个人周报
- [2023年个人周报](https://github.com/superleeyom/blog/issues/52)--2023-01-03
- [2022年个人周报](https://github.com/superleeyom/blog/issues/43)--2022-01-17
Expand All @@ -37,13 +37,14 @@
</details>

## 技术相关
- [Postman如何配置动态端口和IP](https://github.com/superleeyom/blog/issues/56)--2023-12-14
- [解决 IDEA 因为 Clash 代理问题引起的疑难杂症](https://github.com/superleeyom/blog/issues/51)--2022-09-28
- [技术周刊分享](https://github.com/superleeyom/blog/issues/42)--2022-01-13
- [[]如何阅读Apple开发文档](https://github.com/superleeyom/blog/issues/40)--2022-01-08
- [基于Github Issues的博客搭建](https://github.com/superleeyom/blog/issues/38)--2021-09-06
- [对k8s中Service的理解](https://github.com/superleeyom/blog/issues/36)--2021-07-25
<details><summary>显示更多</summary>

- [对k8s中Service的理解](https://github.com/superleeyom/blog/issues/36)--2021-07-25
- [Java空指针避坑指南](https://github.com/superleeyom/blog/issues/35)--2021-07-22
- [业务数据脱敏解决方案探究](https://github.com/superleeyom/blog/issues/32)--2021-07-08
- [为Docker Alpine添加中文字体](https://github.com/superleeyom/blog/issues/29)--2021-04-26
Expand Down
37 changes: 37 additions & 0 deletions backup/56_Postman如何配置动态端口和IP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# [Postman如何配置动态端口和IP](https://github.com/superleeyom/blog/issues/56)

## 背景

起因是每次使用 Postman 调试服务接口的时候,如果服务一旦被重启,对应服务的ip和端口就会改变,就需要重新配置服务的ip和端口,非常的繁琐以及麻烦。所以就针对这个问题,做了一点研究,简单的记录下。

## 步骤

### 1、维护多套环境及相应的环境变量

实际开发中,我们一般会有多套环境,比如:开发环境dev、测试环境test、生产环境prod等等。每个环境,我们配置好对应的consul(注册中心)环境变量、对应服务名环境变量,如图所示:


![image.png](https://cdn.jsdelivr.net/gh/superleeyom/blog/images/1702553954147.png)

### 2、维护collection目录层级以及脚本

建议以服务名为目录,在对应的目录层级,维护如下的脚本,动态的获取注册中心上对应的指定服务的ip和端口:
```js
pm.sendRequest(pm.environment.get("consul_service") + "trade-assets-service",
function(err, res) {
if (err) {
console.log(err);
} else {
pm.environment.set("trade-assets-service", res.json()[0].ServiceAddress + ":" + res.json()[0].ServicePort);
}
});
```

![image.png](https://cdn.jsdelivr.net/gh/superleeyom/blog/images/1702554291804.png)
注: "trade-assets-service" 根据自己目录名变化

### 3、在对应的collection目录模拟request请求

维护好了动态获取脚本后,就可以正常的模拟对应的request请求,请求里面的ip和端口只需要填充对应的服务的占位符即可:

![image.png](https://cdn.jsdelivr.net/gh/superleeyom/blog/images/1702554459873.png)
Loading

0 comments on commit 36d3345

Please sign in to comment.