This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Producer's should be properly managed by the Dropwizard lifecycle. Also fixes incorrect capitalization in the producer package name.
- Loading branch information
1 parent
8e0fa6c
commit dc21341
Showing
4 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../kafka/Producer/InstrumentedProducer.java → .../kafka/producer/InstrumentedProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pwizard/kafka/Producer/KafkaProducer.java → ...pwizard/kafka/producer/KafkaProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ard-extra-kafka/src/main/java/com/datasift/dropwizard/kafka/producer/ManagedProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.datasift.dropwizard.kafka.producer; | ||
|
||
import io.dropwizard.lifecycle.Managed; | ||
import kafka.javaapi.producer.Producer; | ||
|
||
/** | ||
* Manages a Kafka {@link Producer} as part of the application lifecycle.. | ||
*/ | ||
public class ManagedProducer implements Managed { | ||
|
||
private final Producer<?, ?> producer; | ||
|
||
public ManagedProducer(final Producer<?, ?> producer) { | ||
this.producer = producer; | ||
} | ||
|
||
@Override | ||
public void start() throws Exception { | ||
// nothing to do, already started | ||
} | ||
|
||
@Override | ||
public void stop() throws Exception { | ||
producer.close(); | ||
} | ||
} |