Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Apache Pulsar Go Client Library

License

NotificationsYou must be signed in to change notification settings

ggx-trade/pulsar-client-go

 
 

Repository files navigation

PkgGoDevGo Report CardLanguageLICENSE

Apache Pulsar Go Client Library

A Go client library forApache Pulsar. For the supported Pulsar features, seeClient Feature Matrix.

Purpose

This project is a pure-Go client library for Pulsar that does notdepend on the C++ Pulsar library.

Once feature parity and stability are reached, this will supersede the currentCGo-based library.

Requirements

  • Go 1.18+

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 athttps://github.com/apache/pulsar-client-go/projects fortracking 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",})deferclient.Close()producer,err:=client.CreateProducer(pulsar.ProducerOptions{Topic:"my-topic",})_,err=producer.Send(context.Background(),&pulsar.ProducerMessage{Payload: []byte("hello"),})deferproducer.Close()iferr!=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",})deferclient.Close()consumer,err:=client.Subscribe(pulsar.ConsumerOptions{Topic:"my-topic",SubscriptionName:"my-sub",Type:pulsar.Shared,    })deferconsumer.Close()msg,err:=consumer.Receive(context.Background())iferr!=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"})iferr!=nil {log.Fatal(err)}deferclient.Close()reader,err:=client.CreateReader(pulsar.ReaderOptions{Topic:"topic-1",StartMessageID:pulsar.EarliestMessageID(),})iferr!=nil {log.Fatal(err)}deferreader.Close()forreader.HasNext() {msg,err:=reader.Next(context.Background())iferr!=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 GOLANG_VERSION=1.18 PULSAR_VERSION=2.10.0

Contributing

Contributions are welcomed and greatly appreciated. SeeCONTRIBUTING.md for details on submitting patches and the contribution workflow.

If your contribution adds Pulsar features for Go clients, you need to update both thePulsar docs and theClient Feature Matrix. SeeContribution Guide for more details.

Community

Mailing lists
NameScope
users@pulsar.apache.orgUser-related discussionsSubscribeUnsubscribeArchives
dev@pulsar.apache.orgDevelopment-related discussionsSubscribeUnsubscribeArchives
Slack

Pulsar slack channel#dev-go athttps://apache-pulsar.slack.com/

You can self-register athttps://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 yourgo.mod file to the old oauth2 module path. So remove any linessimilar to the following, and then rungo mod tidy.

github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220630195735-e95cf0633348 // indirect

Releases

No releases published

Packages

No packages published

Languages

  • Go99.0%
  • Other1.0%

[8]ページ先頭

©2009-2025 Movatter.jp