Skip to content

Commit edd8ae6

Browse files
Merge #10
10: Remove interrupt-signal handler r=Jaskaranbir a=Jaskaranbir Its better to be implemented by the library-user side. Co-authored-by: Jaskaranbir <jaskaranbir.dhillon@gmail.com>
2 parents dc9eaa2 + cd9bc83 commit edd8ae6

File tree

2 files changed

+0
-48
lines changed

2 files changed

+0
-48
lines changed

kafka/consumer.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ package kafka
22

33
import (
44
"context"
5-
"log"
6-
"os"
7-
"os/signal"
8-
"syscall"
95
"time"
106

117
"github.com/Shopify/sarama"
@@ -70,7 +66,6 @@ func NewConsumer(config *ConsumerConfig) (*Consumer, error) {
7066
consumerGroup: consumerGroup,
7167
topics: config.Topics,
7268
}
73-
consumer.handleKeyInterrupt()
7469
return consumer, nil
7570
}
7671

@@ -98,23 +93,6 @@ func (c *Consumer) SaramaConsumer() *sarama.ConsumerGroup {
9893
return &c.consumerGroup
9994
}
10095

101-
func (c *Consumer) handleKeyInterrupt() {
102-
// Capture the Ctrl+C signal (interrupt or kill)
103-
sigChan := make(chan os.Signal, 1)
104-
signal.Notify(sigChan,
105-
syscall.SIGINT,
106-
syscall.SIGTERM,
107-
syscall.SIGQUIT)
108-
109-
// Elegant exit
110-
go func() {
111-
<-sigChan
112-
log.Println("Keyboard-Interrupt signal received, cleaning up before closing")
113-
closeError := c.consumerGroup.Close()
114-
log.Println(closeError)
115-
}()
116-
}
117-
11896
// Close stops the ConsumerGroup and detaches any running sessions. It is required to call
11997
// this function before the object passes out of scope, as it will otherwise leak memory.
12098
func (c *Consumer) Close() error {

kafka/producer.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package kafka
22

33
import (
4-
"log"
5-
"os"
6-
"os/signal"
7-
"syscall"
8-
94
"github.com/Shopify/sarama"
105
"github.com/pkg/errors"
116
)
@@ -46,26 +41,5 @@ func NewProducer(config *ProducerConfig) (*Producer, error) {
4641
}
4742

4843
asyncProducer := Producer{producer}
49-
asyncProducer.handleKeyInterrupt()
5044
return &asyncProducer, nil
5145
}
52-
53-
func (p *Producer) handleKeyInterrupt() {
54-
// Capture the Ctrl+C signal (interrupt or kill)
55-
sigChan := make(chan os.Signal, 1)
56-
signal.Notify(sigChan,
57-
syscall.SIGINT,
58-
syscall.SIGTERM,
59-
syscall.SIGQUIT)
60-
61-
// Elegant exit
62-
go func() {
63-
<-sigChan
64-
// We always log here, special situation
65-
log.Println("Keyboard-Interrupt signal received.")
66-
err := p.Close()
67-
if err != nil {
68-
log.Println(err.Error())
69-
}
70-
}()
71-
}

0 commit comments

Comments
 (0)