go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

Pubsub subscription only finds messages for "neworder" topic

Open mnussbaum opened this issue 3 years ago • 0 comments

Describe the bug

It appears that the pubsub subscriber can only receive messages for topics named neworder when deployed to a K8s cluster. Any other topic name results in the subscriber not receiving messages.

However, using a local dapr install on my development machine I can use any topic name I want and successfully send and receive messages.

To Reproduce

Using github.com/dapr/go-sdk v1.3.1

pub.go

package main

import (
    "context"
    "fmt"

    dapr "github.com/dapr/go-sdk/client"
)

func main() {
    client, err := dapr.NewClient()
    if err != nil {
        panic(err)
    }
    defer client.Close()

    data := []byte(`{"hi": "there"}`)

    if err := client.PublishEvent(
        context.Background(),
        "pubsub",
        "neworder2",
        data,
    ); err != nil {
        panic(err)
    }
    fmt.Println("data published")
}

sub.go

package main

import (
    "context"
    "log"
    "net/http"

    "github.com/dapr/go-sdk/service/common"
    daprd "github.com/dapr/go-sdk/service/http"
)

var defaultSubscription = &common.Subscription{
    PubsubName: "pubsub",
    Topic:      "neworder2",
    Route:      "/orders",
}

func main() {
    s := daprd.NewService(":8080")

    if err := s.AddTopicEventHandler(defaultSubscription, eventHandler); err != nil
 {
        log.Fatalf("error adding topic subscription: %v", err)
    }

    if err := s.Start(); err != nil && err != http.ErrServerClosed {
        log.Fatalf("error listenning: %v", err)
    }
}

func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error
) {
    log.Printf("event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName,
 e.Topic, e.ID, e.Data)
    return false, nil
}

component k8s yaml:

 apiVersion: dapr.io/v1alpha1
 auth:
   secretStore: <a secret store name>
 kind: Component
 metadata:
   name: pubsub
 spec:
   metadata:
     - name: redisHost
       secretKeyRef:
         key: <a secret key>
         name: <a secret key name>
     - name: redisPassword
       secretKeyRef:
         key: <a secret key>
         name: <a secret key name>
     - name: enableTLS
       value: true
   type: pubsub.redis
   version: v1

Deploy the above to a K8s cluster, run the subscriber in sub.go, and then the publisher in pub.go, and see no messages make it to the subscriber. Change the topic name to neworder, restart the subscriber, rerun the publisher, see messages make it to the subscriber.

I am running dapr version 1.5.1 in my K8s cluster.

Expected behavior

I expected my subscriber to receive messages for any topic name, so long as the publisher and subscriber use the same topic name. This was the behavior in version 1.2.0 of the go-sdk.

mnussbaum avatar Apr 04 '22 20:04 mnussbaum