You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
896 B

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/mq/client/sub_client"
  5. "google.golang.org/grpc"
  6. "google.golang.org/grpc/credentials/insecure"
  7. )
  8. func main() {
  9. subscriberConfig := &sub_client.SubscriberConfiguration{
  10. ClientId: "testSubscriber",
  11. GroupId: "test",
  12. GroupInstanceId: "test",
  13. GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
  14. }
  15. contentConfig := &sub_client.ContentConfiguration{
  16. Namespace: "test",
  17. Topic: "test",
  18. Filter: "",
  19. }
  20. subscriber := sub_client.NewTopicSubscriber("localhost:17777", subscriberConfig, contentConfig)
  21. subscriber.SetEachMessageFunc(func(key, value []byte) bool {
  22. println(string(key), "=>", string(value))
  23. return true
  24. })
  25. subscriber.SetCompletionFunc(func() {
  26. println("done subscribing")
  27. })
  28. if err := subscriber.Subscribe(); err != nil {
  29. fmt.Println(err)
  30. }
  31. }