Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apache/pulsar-client-go
Apache Pulsar Go Client Library
https://github.com/apache/pulsar-client-go
event-streaming go golang messaging pubsub pulsar queuing streaming
Last synced: 5 days ago
JSON representation
Apache Pulsar Go Client Library
- Host: GitHub
- URL: https://github.com/apache/pulsar-client-go
- Owner: apache
- License: apache-2.0
- Created: 2019-05-06T22:08:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-24T07:35:19.000Z (19 days ago)
- Last Synced: 2024-12-31T05:05:00.381Z (12 days ago)
- Topics: event-streaming, go, golang, messaging, pubsub, pulsar, queuing, streaming
- Language: Go
- Homepage: https://pulsar.apache.org/
- Size: 3.38 MB
- Stars: 663
- Watchers: 46
- Forks: 341
- Open Issues: 228
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![PkgGoDev](https://pkg.go.dev/badge/github.com/apache/pulsar-client-go)](https://pkg.go.dev/github.com/apache/pulsar-client-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/apache/pulsar-client-go)](https://goreportcard.com/report/github.com/apache/pulsar-client-go)
[![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/)
[![LICENSE](https://img.shields.io/hexpm/l/pulsar.svg)](https://github.com/apache/pulsar-client-go/blob/master/LICENSE)# Apache Pulsar Go Client Library
A Go client library for [Apache Pulsar](https://pulsar.apache.org/). For the supported Pulsar features, see [Client Feature Matrix](https://pulsar.apache.org/client-feature-matrix/).
## Purpose
This project is 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
- Go 1.20+
> **Note**:
>
> While this library should work with Golang versions as early as 1.16, any bugs specific to versions earlier than 1.18 may not be fixed.## Status
Check the Projects page at https://github.com/apache/pulsar-client-go/projects for
tracking the status and the progress.## Usage
Import the client library:
```go
import "github.com/apache/pulsar-client-go/pulsar"
```Create a Producer:
```go
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:
```go
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:
```go
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 Test
Build the sources:
make build
Run the tests:
make test
Run the tests with specific versions of GOLANG and PULSAR:
make test GO_VERSION=1.20 PULSAR_VERSION=2.10.0
## Contributing
Contributions are welcomed and greatly appreciated. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on submitting patches and the contribution workflow.
If your contribution adds Pulsar features for Go clients, you need to update both the [Pulsar docs](https://pulsar.apache.org/docs/client-libraries/) and the [Client Feature Matrix](https://pulsar.apache.org/client-feature-matrix/). See [Contribution Guide](https://pulsar.apache.org/contribute/site-intro/#pages) for more details.
## Community
##### Mailing lists
| Name | Scope | | | |
| :-------------------------------------------------------- | :------------------------------ | :---------------------------------------------------- | :-------------------------------------------------------- | :----------------------------------------------------------------- |
| [[email protected]](mailto:[email protected]) | User-related discussions | [Subscribe](mailto:[email protected]) | [Unsubscribe](mailto:[email protected]) | [Archives](http://mail-archives.apache.org/mod_mbox/pulsar-users/) |
| [[email protected]](mailto:[email protected]) | Development-related discussions | [Subscribe](mailto:[email protected]) | [Unsubscribe](mailto:[email protected]) | [Archives](http://mail-archives.apache.org/mod_mbox/pulsar-dev/) |##### Slack
Pulsar slack channel `#dev-go` at https://apache-pulsar.slack.com/
You can self-register at https://apache-pulsar.herokuapp.com/
## License
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
## Troubleshooting
### Go module 'ambiguous import' error
If you've upgraded from a previous version of this library, you may run into an 'ambiguous import' error when building.
```
github.com/apache/pulsar-client-go/oauth2: ambiguous import: found package github.com/apache/pulsar-client-go/oauth2 in multiple modules
```The fix for this is to make sure you don't have any references in your `go.mod` file to the old oauth2 module path. So remove any lines
similar to the following, and then run `go mod tidy`.```
github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220630195735-e95cf0633348 // indirect
```