【问题标题】:NatsError: stan: connect request timeout || port forwardingNatsError: stan: 连接请求超时 ||转发端口
【发布时间】:2022-02-03 12:33:02
【问题描述】:

我的 publisher.ts 文件:

import nats from 'node-nats-streaming';

const stan = nats.connect('ticketing', 'abc', {
  url: 'http://localhost:4222',
});

stan.on('connect', () => {
  console.log('Publisher connected to NATS');

  });
});

我的端口转发命令:

kubectl port-forward {nats-deployment pod name} 4222:4222

我的 nats-test 文件夹中的发布命令:

"publish": "ts-node-dev --rs --notify false src/publisher.ts"

我的 nats-depl.yaml 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nats-depl
spec:
  selector:
    matchLabels:
      app: nats
  template:
    metadata:
      labels:
        app: nats
    spec:
      containers:
      - name: nats
        image: nats-streaming:0.17.0
        args: [
          '-p',
          '4222',
          '-m',
          '8222',
          '-hbi',
          '5s',
          '-hbt',
          '5s',
          '-hbf',
          '2',
          '-SD',
          '-cid',
          '-ticketing'
        ]
---
apiVersion: v1
kind: Service
metadata:
  name: nats-srv
spec:
  selector:
    app: nats
  ports:
  - name: client
    protocol: TCP
    port: 4222
    targetPort: 4222
  - name: monitoring
    protocol: TCP
    port: 8222
    targetPort: 8222  

无法连接到 nats 客户端。

【问题讨论】:

  • 什么意思:无法连接nats客户端?你有任何错误,日志吗?请描述到底发生了什么。

标签: node.js docker kubernetes nats-streaming-server


【解决方案1】:

connect 函数的第一个参数是集群 ID。您可以在运行它的容器的日志中检查您的 NATS 集群 ID。集群 ID 图中绿色下划线。

因此,connect 函数应该是:

const stan = nats.connect('test-cluster', 'abc', {
  url: 'http://localhost:4222',
});

代替:

const stan = nats.connect('testing', 'abc', {
  url: 'http://localhost:4222',
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多