1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package main
import (
"fmt"
"log"
"time"
"github.com/seaweedfs/seaweedfs/weed/mq/client/pub_client"
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
)
func main() {
log.Println("Starting SeaweedMQ logging test...")
// Create publisher configuration
config := &pub_client.PublisherConfiguration{
Topic: topic.NewTopic("test", "logging-demo"),
PartitionCount: 3,
Brokers: []string{"127.0.0.1:17777"},
PublisherName: "logging-test-client",
}
log.Println("Creating topic publisher...")
publisher, err := pub_client.NewTopicPublisher(config)
if err != nil {
log.Printf("Failed to create publisher: %v", err)
return
}
defer publisher.Shutdown()
log.Println("Publishing test messages...")
// Publish some test messages
for i := 0; i < 100; i++ {
key := fmt.Sprintf("key-%d", i)
value := fmt.Sprintf("message-%d-timestamp-%d", i, time.Now().Unix())
err := publisher.Publish([]byte(key), []byte(value))
if err != nil {
log.Printf("Failed to publish message %d: %v", i, err)
}
// Small delay to create some connection stress
if i%10 == 0 {
time.Sleep(10 * time.Millisecond)
}
}
log.Println("Finishing publish...")
err = publisher.FinishPublish()
if err != nil {
log.Printf("Failed to finish publish: %v", err)
}
log.Println("Test completed successfully!")
}
|