func (s *Server) ListTopicSubscriptions(ctx context.Context, in *empty.Empty) (*pb.ListTopicSubscriptionsResponse, error) {
	subs := make([]*pb.TopicSubscription, 0)
	for _, v := range s.topicSubscriptions {
		sub := &pb.TopicSubscription{
			PubsubName: v.component,
			Topic:      v.topic,
			Metadata:   v.meta,
		}
		subs = append(subs, sub)
	}
	return &pb.ListTopicSubscriptionsResponse{
		Subscriptions: subs,
	}, nil
}
ListTopicSubscriptions is called by Dapr to get the list of topics in a pubsub component the app wants to subscribe to.
package grpc
import (
	"context"
	"fmt"
	"github.com/golang/protobuf/ptypes/empty"
	"github.com/pkg/errors"
	pb "github.com/dapr/dapr/pkg/proto/runtime/v1"
	"github.com/dapr/go-sdk/service/common"
)
func (s *Server) AddTopicEventHandler(sub *common.Subscription, fn func(ctx context.Context, e *common.TopicEvent) (retry bool, err error)) error {
	if sub == nil {
		return errors.New("subscription required")
	}
	if sub.Topic == "" {
		return errors.New("topic name required")
	}
	if sub.PubsubName == "" {
		return errors.New("pub/sub name required")
	}
	if fn == nil {
		return fmt.Errorf("topic handler required")
	}
	key := fmt.Sprintf("%s-%s", sub.PubsubName, sub.Topic)
	s.topicSubscriptions[key] = &topicEventHandler{
		component: sub.PubsubName,
		topic:     sub.Topic,
		fn:        fn,
		meta:      sub.Metadata,
	}
	return nil
}