본문으로 건너뛰기

기본 설정 및 옵션

기본 설정​

publish, receive(pull) 설정을 통해 메시지를 효율적으로 처리할 수 있습니다.

Publish Settings​
항목설명
DelayThreshold설정한 시간 마다 서버로 publish 요청
- Default : 100ms
CountThreshold설정한 개수 만큼 메시지를 모아서 전송
- Default : 100
NumGoroutines동시에 실행되는 goroutine 개수 제한
- Default: 2
Timeout서버 요청 timeout 시간을 설정
- Default: 60s
FlowControlSettings흐름 제어를 통해 게시 속도를 제어
Receive Settings​
항목설명
NumGoroutines동시에 실행되는 goroutine 개수 제한
- Default: 2
FlowControlSettings흐름 제어를 통해 게시 속도를 제어
FlowControl Settings​
항목설명
MaxOutstandingMessages내부 버퍼에서 처리할 수 있는 메시지의 최대 개수를 지정
- Default: 1000
MaxOutstandingBytes내부 버퍼에서 처리할 수 있는 메시지의 최대 크기를 지정
- Default: 1G
LimitExceededBehavior제한을 초과했을 때의 동작을 정의
• SignalError: 에러 반환
• Block(Default): 제한을 초과하지 않고 요청할 수 있을 때까지 대기
 ㄴ ⚠️ 개별 요청의 대기 시간(latency)이 중요하지 않은 배치 처리에서 유용함
• Ignore: flow control을 사용하지 않음

재시도​

gRPC 호출 시 응답 값이 설정한 에러에 해당하는 경우, 다시 호출을 시도합니다. 재시도는 설정된 재시도 설정 항목에 따라 실행됩니다. API별로 기본적으로 재시도하는 응답과 설정은 다음과 같습니다.

재시도 에러 상태 코드​

자세한 내용은 GRPC Github를 참고하시기 바랍니다.

항목설명
CANCELLED호출이 취소된 경우(보통 호출하는 곳에서 취소한 경우)
UNKNOWN알 수 없는 에러, 예를 들어 다른 주소에서 받은 상태 값이 해당 주소에서 정의되지 않은 경우 이 오류가 반환될 수 있음
- 또한 응답 오류에 대한 정보를 제공하지 않는 API인 경우에도 해당
DEADLINE_EXCEEDED호출이 완료되기 전에 데드라인이 만료됨
NOT_FOUND일부 요청한 엔티티(예: 파일 또는 경로)를 찾을 수 없음
RESOURCE_EXHAUSTED일부 리소스가 소진되었거나 사용자당 할당량이 부족하거나 전체 파일 시스템의 공간이 부족한 경우
ABORTED일반적으로 Sequencer Check에 실패하거나 트랜잭션 중간과 같은 동시성 문제로 작업이 중단된 경우
INTERNAL내부 오류
UNAVAILABLE현재 서비스를 이용할 수 없음
재시도 설정 항목​
항목설명
Initialretry를 처음 하기 전에 설정할 delay
- Multiplier에 따라 조정된 값을 사용
Multiplier다음 호출 retry delay = 이전 호출의 retry delay * Multiplier
Maxretry delay의 제한을 설정
⚠️ Multiplier는 retry delay를 이 값을 초과하여 설정할 수 없음
Publisher Retry Default Setting​
APIRetry code설명Retry setting
create topic14     UNAVAILABLE• Initial : 100ms
• Multiplier : 1.3
• Max : 60s
get topic14UNAVAILABLE
list topics14UNAVAILABLE
list topic subscriptions14UNAVAILABLE
update topic14UNAVAILABLE
delete topic14UNAVAILABLE
publish1CANCELLED
4DEADLINE_EXCEEDED
8RESOURCE_EXHAUSTED
13INTERNAL
14UNAVAILABLE
Subscriber Retry Default Settings​
APIRetry code설명Retry setting
create subscription14     UNAVAILABLE• Initial : 100ms
• Multiplier : 1.3
• Max : 60s
get subscription14UNAVAILABLE
list subscriptions14UNAVAILABLE
seek14UNAVAILABLE
update subscription14UNAVAILABLE
delete subscription14UNAVAILABLE
modify ack deadline14UNAVAILABLE
acknowledge14UNAVAILABLE
pull14UNAVAILABLE
streaming pull4DEADLINE_EXCEEDED
8RESOURCE_EXHAUSTED
13INTERNAL
14UNAVAILABLE
Custom retry configuration example
cfg := &pubsub.ClientConfig{
PublisherCallOptions: &api.PublisherCallOptions{
Publish: []option.CallOption{
option.WithRetryOptions(
option.WithCodes(codes.ResourceExhausted),
option.WithBackoff(option.Backoff{
Initial: 100 * time.Millisecond,
Max: 30000 * time.Millisecond,
Multiplier: 1.20,
})),
},
},
SubscriberCallOptions: &api.SubscriberCallOptions{
StreamingPull: []option.CallOption{
option.WithRetryOptions(
option.WithCodes(codes.ResourceExhausted),
option.WithBackoff(option.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})),
},
},
}
client, err := NewClientWithConfig(ctx, domainID, projectID, conf, opts...)

로깅​

Publish 및 StreamingPull에서 요청 및 응답(성공/실패)에 대한 로그를 통계성 로그를 남길 수 있습니다.

  • 시간 간격을 설정한 경우, 해당 간격마다 publish, pull의 성공/실패 횟수가 출력됩니다.
  • 출력을 확인하려는 경우, info level 이상으로 설정해야 합니다.

Logger에는 기본적으로 다음 값을 설정할 수 있습니다.

항목설명
Level로그의 레벨
- 기본값: Panic
Output로그의 아웃풋
- 기본값: os.Stdout
StatLogInterval로그를 남길 시간 간격
로깅 예시
conf := &ClientConfig{
LogOptions: &LogOptions{
Level: "info",
Output: os.Stdout,
StatLogInterval: 1 * time.Second
}
}
client, err := NewClientWithConfig(ctx, domainID, projectID, conf, opts...)