kubernetes - 在 minikube 上运行的微服务应用程序正在运行,但未显示评论部分
问题描述
我在 win 10 home 并使用带有 minikube 的 docker 工具箱。这是一个基于微服务架构的应用程序,因此文件很多,但以下是我认为有问题的文件。整个应用程序正在运行,刷新时会显示帖子,但没有出现评论。我没有使用任何数据库。所有数据都保存在内存中。
这在将 ingress-nginx 初始化到应用程序后开始发生
预期行为:
- 添加帖子并刷新页面以查看新帖子
- 向帖子添加评论并刷新以查看新评论
脚步:
1. 在前端/commentCreate.jsx
const onSubmit = async (event) => {
event.preventDefault();
await axios.post(`http://posts.com/posts/${postId}/comments/create`, {
content,
});
setContent("");
};
2.在comments/index.js中
app.post('/posts/:id/comments/create', async (req, res) => {
...
commentsByPost[req.params.id] = comments
await axios.post('http://event-bus-int-serv:5000/events',{
type: 'CommentCreated',
data: {
id: commentId,
content,
postId: req.params.id,
status: 'pending'
}
})
res.status(201).json(comments)
})
3. 在 event-bus/index.js
app.post('/events', (req,res) => {
...
axios.post('http://posts-int-serv:4000/events', event).catch(err => console.log(err.message))
axios.post('http://comments-int-serv:4100/events', event).catch(err => console.log(err.message))
axios.post('http://query-int-serv:4200/events', event).catch(err => console.log(err.message))
axios.post('http://moderation-int-serv:4300/events', event).catch(err => console.log(err.message))
res.send({status: 'OK'})
})
4.在query/index.js中
const posts={}
const handleEvent = (type, data) => {
...
if(type==="CommentCreated"){
const {id,content,postId, status} = data
const post = posts[postId]
post.comments.push({
id, content, status
})
console.log("post",post)
}
}
app.get('/posts', (req,res) => {
console.log("posts query get: ",posts)
res.send(posts)
})
app.post('/events', (req,res) => {
const {type, data} = req.body
handleEvent(type, data)
res.send({})
})
可能的根本问题:
commentCreated 块中的 console.log("post",post) 显示了整个帖子及其评论,但似乎 app.get('/posts', (req,res) 不起作用,因为它的控制台日志没有显示
我检查了入口中的路由,我认为它是正确的。要到达 app.get('/posts', (req,res),我需要使用端口 4200,这是我为查询服务提供的端口号
入口服务 yml 配置的一部分
- path: /posts
pathType: Prefix
backend:
service:
name: query-serv
port:
number: 4200
为了进一步参考,这是我的仓库中的全部代码:
https://github.com/JohnLawliet/microservices
任何帮助是极大的赞赏。
解决方案
推荐阅读
- python-3.x - 在 Windows 上安装 geograpy3
- firebase - 电话身份验证 Firebase 的定义
- python - 如何在 Django 的用户扩展模型中上传个人资料图片
- python - 注册 - 序列项 0:预期的 str 实例,找到 NoneType
- java-8 - 这是在 Java 中使用 Optional 的正确方法吗?
- neo4j - 如何在 Neo4j 中同时创建一个节点并在查询中使用该节点?
- spring - 如何正确处理 JwtException.?
- symfony - $request 对于生产环境为空
- amazon-web-services - 具有策略分配的 terraform aws iam 角色
- apache-kafka - Kafka 错误 - 这不是正确的协调器