找不到消息总线 pubsub。jetstream/v1 Dapr

Couldn't find message bus pubsub.jetstream/v1 Dapr

我正在尝试将 dapr 与启用了 jetstream 功能的 nats 连接起来。

我想用 docker-compose 开始一切。 Nats 服务已启动,当我 运行 nats-cli 使用命令 nats -s "nats://localhost:4222" server check jetstream 时,我得到 OK JetStream | memory=0B memory_pct=0%;75;90 storage=0B storage_pct=0%;75;90 streams=0 streams_pct=0% consumers=0 consumers_pct=0% 表明 nats with jetstream 工作正常。

不幸的是,dapr returns 先是警告然后是错误

警告:error creating pub sub %!s(*string=0xc0000ca020) (pubsub.jetstream/v1): couldn't find message bus pubsub.jetstream/v1" app_id=conversation-api1 instance=50b51af8e9a8 scope=dapr.runtime type=log ver=1.3.0

错误:process component conversation-pubsub error: couldn't find message bus pubsub.jetstream/v1" app_id=conversation-api1 instance=50b51af8e9a8 scope=dapr.runtime type=log ver=1.3.0

我遵循了 official site 上的说明。

docker-compose.yaml

version: '3.4'

services:
  conversation-api1:
    image: ${DOCKER_REGISTRY-}conversationapi1
    build:
      context: .
      dockerfile: Conversation.Api1/Dockerfile
    ports:
      - "5010:80"

  conversation-api1-dapr:
    container_name: conversation-api1-dapr
    image: "daprio/daprd:latest"
    command: [ "./daprd", "--log-level", "debug", "-app-id", "conversation-api1", "-app-port", "80", "--components-path", "/components", "-config", "/configuration/conversation-config.yaml" ]    
    volumes:
      - "./dapr/components/:/components"
      - "./dapr/configuration/:/configuration"
    depends_on:
      - conversation-api1
      - redis
      - nats
    network_mode: "service:conversation-api1"

  nats:
    container_name: "Nats"
    image: nats
    command: [ "-js", "-m", "8222" ]
    ports:
      - "4222:4222"
      - "8222:8222"
      - "6222:6222"
# OTHER SERVICES...

对话-pubsub.yaml

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: conversation-pubsub
  namespace: default
spec:
  type: pubsub.jetstream
  version: v1
  metadata:
  - name: natsURL
    value: "nats://host.docker.internal:4222" # already tried with nats for host
  - name: name
    value: "conversation"
  - name: durableName
    value: "conversation-durable"
  - name: queueGroupName
    value: "conversation-group"
  - name: startSequence
    value: 1
  - name: startTime # in Unix format
    value: 1630349391
  - name: deliverAll
    value: false
  - name: flowControl
    value: false

对话-config.yaml

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: config
  namespace: default
spec:
  tracing:
    samplingRate: "1"
    zipkin:
      endpointAddress: "http://zipkin:9411/api/v2/spans"

问题出在旧的 Dapr 版本中。我使用的版本 1.3.0,Jetstream 支持在 1.4.0+ 中引入。拉取最新版本的 daprio/daprd 解决了我的问题。也不需要 nats://host.docker.internal:4222nats://nats:4222 按预期工作。