Go 클라이언트 초기화
Go 클라이언트 초기화 (Go client initialize)
Go Pulsar 클라이언트를 초기화하는 것은 NewClient로 Client 객체를 만드는 것에서 시작해요. ClientOptions 객체를 넘기며 클라이언트를 만들 수 있고, 단일 브로커뿐 아니라 여러 브로커를 한 번에 지정할 수도 있어요.
출처: 문서
본문
Pulsar와 상호작용하려면 먼저 Client 객체가 필요해요. NewClient 함수에 ClientOptions 객체를 전달해 클라이언트 객체를 만들 수 있어요. 다음은 예시예요.
import (
"log"
"time"
"github.com/apache/pulsar-client-go/pulsar"
)
func main() {
client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650",
OperationTimeout: 30 * time.Second,
ConnectionTimeout: 30 * time.Second,
})
if err != nil {
log.Fatalf("Could not instantiate Pulsar client: %v", err)
}
defer client.Close()
}
여러 브로커가 있다면 아래와 같이 클라이언트 객체를 만들 수 있어요.
import (
"log"
"time"
"github.com/apache/pulsar-client-go/pulsar"
)
func main() {
client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650,localhost:6651,localhost:6652",
OperationTimeout: 30 * time.Second,
ConnectionTimeout: 30 * time.Second,
})
if err != nil {
log.Fatalf("Could not instantiate Pulsar client: %v", err)
}
defer client.Close()
}
구성 가능한 모든 파라미터는 ClientOptions를 참고하세요.
더 알아보기 (Learn more)
- Go 클라이언트 라이브러리 설정 — Go 클라이언트를 설치하는 방법을 알아봐요.
- Go 클라이언트 사용 — 프로듀서와 컨슈머를 만들어 사용하는 방법을 살펴봐요.
- Go 클라이언트 — Go 클라이언트 개요를 확인해요.
- 클라이언트 작업 — 클라이언트로 할 수 있는 작업을 알아봐요.