pulsar-admin CLI 도구 시작하기

pulsar-admin CLI 도구 시작하기

이 튜토리얼은 pulsar-admin CLI로 토픽을 관리하는 전 과정을 단계별로 안내해요. 서비스 URL 설정부터 시작해 파티션 토픽 생성, 파티션 수 갱신, 메시지 생산, 토픽 통계 확인, 토픽 삭제까지 순서대로 진행돼요.

명령을 하나씩 실행하고 출력을 확인하다 보면 pulsar-admin의 전형적인 사용 패턴이 자연스럽게 익숙해질 거예요.

출처: 문서

본문

이 튜토리얼은 pulsar-admin CLI로 토픽을 관리하는 모든 단계를 안내해요. 다음 단계로 구성돼요.

  • 서비스 URL 설정
  • 파티션 토픽 생성
  • 파티션 수 갱신
  • 토픽에 메시지 생산
  • 토픽 통계 확인
  • 토픽 삭제

사전 준비 (Prerequisites)

  • Pulsar standalone 설치 및 시작. 이 튜토리얼은 예시로 Pulsar 2.11을 실행해요.

단계 (Steps)

  1. client.conf에서 서비스 URL이 브로커 서비스를 가리키도록 설정해요.
webServiceUrl=http://localhost:8080/
brokerServiceUrl=pulsar://localhost:6650/
  1. 파티션이 6개인 test-topic-1이라는 지속(persistent) 토픽을 만들어요.

입력:

bin/pulsar-admin topics create-partitioned-topic \
persistent://public/default/test-topic-1 \
--partitions 6

출력:

출력은 없어요. 토픽의 상태는 5단계에서 확인할 수 있어요.

  1. 파티션 수를 8로 갱신해요.

입력:

bin/pulsar-admin topics update-partitioned-topic \
persistent://public/default/test-topic-1 \
--partitions 8

출력:

출력은 없어요. 파티션 수는 5단계에서 확인할 수 있어요.

  1. 파티션 토픽 test-topic-1에 몇 개의 메시지를 생산해요.

입력:

bin/pulsar-perf produce -u pulsar://localhost:6650 -r 1000 -i 1000 persistent://public/default/test-topic-1

출력:

{
  "confFile" : "/Users/yu/apache-pulsar-2.11.0/conf/client.conf",
  "serviceURL" : "pulsar://localhost:6650",
  "authPluginClassName" : "",
  "authParams" : "",
  "tlsTrustCertsFilePath" : "",
  "tlsAllowInsecureConnection" : false,
  "tlsHostnameVerificationEnable" : false,
  "maxConnections" : 1,
  "statsIntervalSeconds" : 1000,
  "ioThreads" : 1,
  "enableBusyWait" : false,
  "listenerName" : null,
  "listenerThreads" : 1,
  "maxLookupRequest" : 50000,
  "topics" : [ "persistent://public/default/test-topic-1" ],
  "numTestThreads" : 1,
  "msgRate" : 1000,
  "msgSize" : 1024,
  "numTopics" : 1,
"numProducers" : 1,
  "separator" : "-",
  "sendTimeout" : 0,
  "producerName" : null,
  "adminURL" : "http://localhost:8080/",

...
}
  1. 파티션 토픽 test-topic-1의 내부 통계를 확인해요.

입력:

bin/pulsar-admin topics partitioned-stats-internal \
persistent://public/default/test-topic-1

출력:

아래는 출력의 일부예요. 토픽 통계에 대한 자세한 설명은 Pulsar 통계를 참고해요.

{
  "metadata" : {
    "partitions" : 8
  },
  "partitions" : {
    "persistent://public/default/test-topic-1-partition-1" : {
      "entriesAddedCounter" : 4213,
      "numberOfEntries" : 4213,
      "totalSize" : 8817693,
      "currentLedgerEntries" : 4212,
      "currentLedgerSize" : 8806289,
      "lastLedgerCreatedTimestamp" : "2023-03-07T15:33:59.367+08:00",
      "waitingCursorsCount" : 0,
      "pendingAddEntriesCount" : 0,
      "lastConfirmedEntry" : "65:4211",
      "state" : "LedgerOpened",
      "ledgers" : [ {
        "ledgerId" : 49,
        "entries" : 1,
        "size" : 11404,
        "offloaded" : false,
        "underReplicated" : false
      }, {
        "ledgerId" : 65,
        "entries" : 0,
        "size" : 0,
        "offloaded" : false,
        "underReplicated" : false
      } ],
      "cursors" : {
        "test-subscriptio-1" : {
          "markDeletePosition" : "49:-1",
          "readPosition" : "49:0",
          "waitingReadOp" : false,
          "pendingReadOps" : 0,
          "messagesConsumedCounter" : 0,
          "cursorLedger" : -1,
          "cursorLedgerLastEntry" : -1,
  "individuallyDeletedMessages" : "[]",
          "lastLedgerSwitchTimestamp" : "2023-03-06T16:41:32.801+08:00",
          "state" : "NoLedger",
          "numberOfEntriesSinceFirstNotAckedMessage" : 1,
          "totalNonContiguousDeletedMessagesRange" : 0,
          "subscriptionHavePendingRead" : false,
          "subscriptionHavePendingReplayRead" : false,
          "properties" : { }
        },
        "test-subscription-1" : {
          "markDeletePosition" : "49:-1",
          "readPosition" : "49:0",
          "waitingReadOp" : false,
          "pendingReadOps" : 0,
          "messagesConsumedCounter" : 0,
          "cursorLedger" : -1,
          "cursorLedgerLastEntry" : -1,
          "individuallyDeletedMessages" : "[]",
          "lastLedgerSwitchTimestamp" : "2023-03-06T16:41:32.801+08:00",
          "state" : "NoLedger",
          "numberOfEntriesSinceFirstNotAckedMessage" : 1,
          "totalNonContiguousDeletedMessagesRange" : 0,
          "subscriptionHavePendingRead" : false,
          "subscriptionHavePendingReplayRead" : false,
          "properties" : { }
        }
      },
      "schemaLedgers" : [ ],
      "compactedLedger" : {
        "ledgerId" : -1,
        "entries" : -1,
        "size" : -1,
        "offloaded" : false,
        "underReplicated" : false
      }
    },
...
  1. 토픽 test-topic-1을 삭제해요.

입력:

bin/pulsar-admin topics delete-partitioned-topic persistent://public/default/test-topic-1

출력:

출력은 없어요. 다음 명령으로 test-topic-1이 존재하는지 확인할 수 있어요.

입력: public/default 네임스페이스의 토픽을 나열해요.

bin/pulsar-admin topics list public/default

pulsar-admin CLI의 자세한 사용법은 pulsar-admin CLI 레퍼런스를 참고해요.

더 알아보기 (Learn more)

  • pulsar-admin CLI 전체 명령어는 pulsar-admin CLI 레퍼런스 문서에서 확인해요.
  • 토픽 통계의 자세한 의미는 Pulsar 통계 문서를 살펴보세요.
  • 파티션 토픽 개념이 궁금하다면 파티션 토픽 문서를 참고해요.