MCPcopy Index your code
hub / github.com/apache/pulsar-client-go

github.com/apache/pulsar-client-go @v0.20.0-candidate-1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.20.0-candidate-1 ↗ · + Follow
5,731 symbols 19,572 edges 300 files 1,397 documented · 24% 11 cross-repo links updated 9d agov0.20.0 · 2026-06-15★ 744198 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PkgGoDev Go Report Card Language LICENSE

Apache Pulsar Go Client Library

A Go client library for Apache Pulsar. For the supported Pulsar features, see 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.24+

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:

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 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.24 PULSAR_VERSION=4.0.3

Contributing

Contributions are welcomed and greatly appreciated. See 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 and the Client Feature Matrix. See Contribution Guide for more details.

Community

Mailing lists
Name Scope
users@pulsar.apache.org User-related discussions Subscribe Unsubscribe Archives
dev@pulsar.apache.org Development-related discussions Subscribe Unsubscribe Archives
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

Extension points exported contracts — how you extend this code

TopicMessageID (Interface)
TopicMessageID defined the correspondence between topic and MessageID. [10 implementers]
pulsar/message.go
Consumer (Interface)
Consumer is an interface that abstracts behavior of Pulsar's consumer [5 implementers]
pulsar/consumer.go
NackBackoffPolicy (Interface)
NackBackoffPolicy is a interface for custom message negativeAcked policy, users can specify a NackBackoffPolicy for a co [5 …
pulsar/negative_backoff_policy.go
Entry (Interface)
Entry describes the interface for the logger entry. [5 implementers]
pulsar/log/logger.go
HTTPAuthProvider (Interface)
(no doc) [11 implementers]
pulsar/auth/provider.go
HTTPClient (Interface)
(no doc) [9 implementers]
pulsar/internal/http_client.go
Clock (Interface)
Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time. [3 implementers]
oauth2/clock/clock.go
ConsumerInterceptor (Interface)
(no doc) [5 implementers]
pulsar/consumer_interceptor.go

Core symbols most depended-on inside this repo

Close
called by 527
pulsar/reader.go
endpoint
called by 316
pulsaradmin/pkg/admin/admin.go
String
called by 295
pulsar/message.go
NewClient
called by 288
pulsar/client.go
Error
called by 283
pulsar/log/logger.go
CreateProducer
called by 273
pulsar/client.go
Close
called by 267
pulsar/client.go
Subscribe
called by 218
pulsar/client.go

Shape

Method 4,027
Function 1,067
Struct 494
Interface 79
TypeAlias 61
FuncType 3

Languages

Go100%

Modules by API surface

pulsar/internal/pulsar_proto/PulsarApi.pb.go979 symbols
pulsaradmin/pkg/admin/topic.go438 symbols
pulsaradmin/pkg/admin/namespace.go399 symbols
pulsaradmin/pkg/admin/topic_policies.go172 symbols
pulsar/consumer_test.go154 symbols
pulsar/consumer_partition.go126 symbols
pulsaradmin/pkg/admin/functions.go97 symbols
pulsar/producer_test.go94 symbols
pulsar/schema.go89 symbols
pulsar/internal/connection.go87 symbols
pulsaradmin/pkg/admin/sources.go73 symbols
pulsaradmin/pkg/admin/sinks.go73 symbols

For agents

$ claude mcp add pulsar-client-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page