在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:apache/pulsar-client-go开源软件地址:https://github.com/apache/pulsar-client-go开源编程语言:Go 98.8%开源软件介绍:Apache Pulsar Go Client LibraryA Go client library for the Apache Pulsar project. GoalThis projects is developing a pure-Go client library for Pulsar that does not depend on the C++ Pulsar library. Once feature parity and stability are reached, this will supersede the current CGo based library. Requirements
StatusCheck the Projects page at https://github.com/apache/pulsar-client-go/projects for tracking the status and the progress. UsageImport the client library: import "github.com/apache/pulsar-client-go/pulsar" Create a Producer: client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650",
})
defer client.Close()
producer, err := client.CreateProducer(pulsar.ProducerOptions{
Topic: "my-topic",
})
_, err = producer.Send(context.Background(), &pulsar.ProducerMessage{
Payload: []byte("hello"),
})
defer producer.Close()
if err != nil {
fmt.Println("Failed to publish message", err)
} else {
fmt.Println("Published message")
} Create a Consumer: client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650",
})
defer client.Close()
consumer, err := client.Subscribe(pulsar.ConsumerOptions{
Topic: "my-topic",
SubscriptionName: "my-sub",
Type: pulsar.Shared,
})
defer consumer.Close()
msg, err := consumer.Receive(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
msg.ID(), string(msg.Payload())) Create a Reader: client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"})
if err != nil {
log.Fatal(err)
}
defer client.Close()
reader, err := client.CreateReader(pulsar.ReaderOptions{
Topic: "topic-1",
StartMessageID: pulsar.EarliestMessageID(),
})
if err != nil {
log.Fatal(err)
}
defer reader.Close()
for reader.HasNext() {
msg, err := reader.Next(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
msg.ID(), string(msg.Payload()))
} Build and TestBuild the sources:
Run the unit tests:
ContributingContributions are welcomed and greatly appreciated. See CONTRIBUTING.md for details on submitting patches and the contribution workflow. ContactMailing lists
SlackPulsar slack channel You can self-register at https://apache-pulsar.herokuapp.com/ LicenseLicensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论