-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SigNoz/docker-setup
some more fixes
- Loading branch information
Showing
13 changed files
with
20 additions
and
34 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
Binary file not shown.
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
Binary file modified
BIN
-580 Bytes
(92%)
kafka-app-otel/common/target/classes/io/shivanshuraj1333/kafka/otel/BaseConsumer.class
Binary file not shown.
Binary file modified
BIN
+3.6 KB
(180%)
kafka-app-otel/common/target/classes/io/shivanshuraj1333/kafka/otel/BaseProducer.class
Binary file not shown.
Binary file not shown.
43 changes: 16 additions & 27 deletions
43
kafka-app-otel/kafka-consumer/src/main/java/io/shivanshuraj1333/kafka/otel/Consumer.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 |
---|---|---|
@@ -1,61 +1,50 @@ | ||
package io.shivanshuraj1333.kafka.otel; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class Consumer extends BaseConsumer { | ||
|
||
public static void main(String[] args) { | ||
Consumer consumer = new Consumer(); | ||
CountDownLatch latch = new CountDownLatch(1); | ||
|
||
try { | ||
// Load configuration from environment variables | ||
consumer.loadConfiguration(System.getenv()); | ||
|
||
// Load Kafka consumer properties | ||
Properties props = consumer.loadKafkaConsumerProperties(); | ||
consumer.createKafkaConsumer(props); | ||
|
||
// Start the consumer thread | ||
Thread consumerThread = new Thread(() -> { | ||
try { | ||
consumer.run(latch); | ||
log.info("Starting Kafka consumer thread..."); | ||
consumer.run(); // No latch needed, directly run the consumer | ||
} catch (Exception e) { | ||
log.error("Error occurred while running Kafka consumer: ", e); | ||
} finally { | ||
log.info("Kafka consumer thread has exited."); | ||
} | ||
}); | ||
|
||
consumerThread.start(); | ||
|
||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
log.info("Shutdown hook triggered, stopping the consumer..."); | ||
consumer.running.set(false); | ||
// Keep the main thread alive indefinitely to prevent the application from exiting | ||
log.info("Application is running. Press Ctrl+C to exit."); | ||
|
||
// Use an infinite loop to keep the application alive | ||
while (true) { | ||
try { | ||
if (!latch.await(10000, TimeUnit.MILLISECONDS)) { | ||
log.warn("Consumer did not shut down gracefully within the timeout."); | ||
} else { | ||
log.info("Consumer shut down gracefully."); | ||
} | ||
Thread.sleep(1000); // Sleep to reduce CPU usage | ||
} catch (InterruptedException e) { | ||
log.error("Interrupted while waiting for consumer to shut down.", e); | ||
log.error("Main thread interrupted. Exiting application.", e); | ||
Thread.currentThread().interrupt(); | ||
break; | ||
} | ||
})); | ||
} | ||
|
||
log.info("Application is running. Press Ctrl+C to exit."); | ||
latch.await(); | ||
} catch (Exception e) { | ||
log.error("Unexpected error in main method: ", e); | ||
} finally { | ||
try { | ||
latch.countDown(); | ||
} catch (Exception e) { | ||
log.error("Error during final latch countdown: ", e); | ||
} | ||
log.info("Application has exited."); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
Oops, something went wrong.