More Lifecycle Polishing

- `null` the consumer on `stop()`
- set `running` to true on first receive if needed
This commit is contained in:
Gary Russell
2018-01-23 16:33:48 -05:00
committed by Artem Bilan
parent 28b4dd814c
commit a997740c29

View File

@@ -262,6 +262,7 @@ public class KafkaMessageSource<K, V> extends AbstractMessageSource<Object>
synchronized (this.consumerMonitor) {
if (this.consumer != null) {
this.consumer.close(30, TimeUnit.SECONDS);
this.consumer = null;
}
}
this.running = false;
@@ -307,8 +308,8 @@ public class KafkaMessageSource<K, V> extends AbstractMessageSource<Object>
}
protected void createConsumer() {
this.consumer = this.consumerFactory.createConsumer(this.groupId, this.clientId, null);
synchronized (this.consumerMonitor) {
this.consumer = this.consumerFactory.createConsumer(this.groupId, this.clientId, null);
this.consumer.subscribe(Arrays.asList(this.topics), new ConsumerRebalanceListener() {
@Override
@@ -332,6 +333,7 @@ public class KafkaMessageSource<K, V> extends AbstractMessageSource<Object>
}
});
this.running = true;
}
}