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.

59 lines
1.3 KiB

1 year ago
1 year ago
1 year ago
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  7. "google.golang.org/grpc"
  8. "google.golang.org/grpc/credentials/insecure"
  9. )
  10. func main() {
  11. err := pb.WithBrokerGrpcClient(true,
  12. "localhost:17777",
  13. grpc.WithTransportCredentials(insecure.NewCredentials()),
  14. func(client mq_pb.SeaweedMessagingClient) error {
  15. pubClient, err := client.Publish(context.Background())
  16. if err != nil {
  17. return err
  18. }
  19. if initErr := pubClient.Send(&mq_pb.PublishRequest{
  20. Message: &mq_pb.PublishRequest_Init{
  21. Init: &mq_pb.PublishRequest_InitMessage{
  22. Topic: &mq_pb.Topic{
  23. Namespace: "test",
  24. Name: "test",
  25. },
  26. Partition: &mq_pb.Partition{
  27. RangeStart: 0,
  28. RangeStop: 1,
  29. RingSize: 1,
  30. },
  31. },
  32. },
  33. }); initErr != nil {
  34. return initErr
  35. }
  36. for i := 0; i < 10; i++ {
  37. if dataErr := pubClient.Send(&mq_pb.PublishRequest{
  38. Message: &mq_pb.PublishRequest_Data{
  39. Data: &mq_pb.DataMessage{
  40. Key: []byte(fmt.Sprintf("key-%d", i)),
  41. Value: []byte(fmt.Sprintf("value-%d", i)),
  42. },
  43. },
  44. }); dataErr != nil {
  45. return dataErr
  46. }
  47. }
  48. return nil
  49. })
  50. if err != nil {
  51. fmt.Println(err)
  52. }
  53. }