Skip to content

Commit 1381f0a

Browse files
guyinyouguyinyou
andauthored
golang: add SetRequestTimeout implements producer/simpleConsumer/pushConsumer (#1016)
Co-authored-by: guyinyou <[email protected]>
1 parent 7da326f commit 1381f0a

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

golang/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Client interface {
4646

4747
type isClient interface {
4848
isClient()
49+
SetRequestTimeout(timeout time.Duration)
4950
wrapHeartbeatRequest() *v2.HeartbeatRequest
5051
onRecoverOrphanedTransactionCommand(endpoints *v2.Endpoints, command *v2.RecoverOrphanedTransactionCommand) error
5152
onVerifyMessageCommand(endpoints *v2.Endpoints, command *v2.VerifyMessageCommand) error

golang/producer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,8 @@ func (p *defaultProducer) onRecoverOrphanedTransactionCommand(endpoints *v2.Endp
455455
func (p *defaultProducer) onVerifyMessageCommand(endpoints *v2.Endpoints, command *v2.VerifyMessageCommand) error {
456456
return nil
457457
}
458+
459+
func (p *defaultProducer) SetRequestTimeout(timeout time.Duration) {
460+
p.cli.opts.timeout = timeout
461+
p.pSetting.requestTimeout = p.cli.opts.timeout
462+
}

golang/push_consumer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ type defaultPushConsumer struct {
7070
consumptionErrorQuantity atomic.Int64
7171
}
7272

73+
func (pc *defaultPushConsumer) SetRequestTimeout(timeout time.Duration) {
74+
pc.cli.opts.timeout = timeout
75+
pc.pcSettings.requestTimeout = pc.cli.opts.timeout
76+
}
77+
7378
func (pc *defaultPushConsumer) isOn() bool {
7479
return pc.cli.on.Load()
7580
}

golang/simple_consumer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ type defaultSimpleConsumer struct {
6161
subTopicRouteDataResultCache sync.Map
6262
}
6363

64+
func (sc *defaultSimpleConsumer) SetRequestTimeout(timeout time.Duration) {
65+
sc.cli.opts.timeout = timeout
66+
sc.scSettings.requestTimeout = sc.cli.opts.timeout
67+
}
68+
6469
func (sc *defaultSimpleConsumer) isOn() bool {
6570
return sc.cli.on.Load()
6671
}

0 commit comments

Comments
 (0)