goeh / weather-collector

This Java program read data from a weather station (Davis Vantage Pro2) and store it in a SQL database
5 stars 3 forks source link

application non running main method in new class created #8

Closed saveriogzz closed 3 years ago

saveriogzz commented 3 years ago

Hi @goeh !

This is not an issue regarding the application's code but probably something related to Java and its mechanisms. I created this new set of packages to stream data to an Apache Pulsar cluster but at the moment this won't work: the application runs without problems but nothing from the DavisProducer class is called. Would you possibly know how to fix it?

Thanks

goeh commented 3 years ago

The main class is specified in build.gradle. If you change that to your main class it should call your class. https://github.com/saveriogzz/weather-collector/blob/pulsar-simple-schema/build.gradle#L13

saveriogzz commented 3 years ago

alright thanks! I will make sure to call your classes and methods to get the console's data and then stream them.

goeh commented 3 years ago

In my setup I store the data in MySQL, but also send the data to an external REST service. If you can make that configurable in some way, then we could configure how data should be distributed once downloaded from the weather station. See https://github.com/goeh/weather-collector/blob/a3d8af143de92830ccd4bffac053c40b36c94cc5/src/main/java/se/technipelago/weather/vantagepro/DownloadController.java#L311

saveriogzz commented 3 years ago

Thanks Goran! To give you an idea of how I would like to stream the data, you can look at my branch. I tried to define some classes and methods that I want to use for streaming data but I never worked with Java before!

goeh commented 3 years ago

One key question is: Do you need to store the data in MySQL at all? Would it be ok to just download the data and stream it? In that case you should be able to create a subclass of DataStore and use that custom datastore only. But if you want to store the data in a database and then stream it, you need to have both the SqlDataStore and your custom datastore configured. The "remote" and "opensensor" datastores are kind of hard coded. There is room for improvement there to make the configuration of data stores much more flexible. The design goal when I started the project was to have configurable data stores (i.e. backends) but once I got the sql and opensensor datastores working I did not spend much time on that goal. I'm happy that you are willing to add another "data store" to the system. I'll help as much as I can but my time is limited. Very busy at work right now. But I do have time to answer questions. So keep up the good work!

saveriogzz commented 3 years ago

Short answer: no, I don't need it!
Long Answer: I don't need it because what I'm trying to implement is a producer for a pub/sub platform (Apache Pulsar) where every message sent to the apache pulsar cluster will be sinked into another database (Cassandra).

Thanks a lot for the insights above, I have now a clearer idea on how things work with the DataStore interface!
One further simple question is: in order to parse a new properties file for the newly implemented datastore, should I just specify that as a variable and place it in the classpath?

Thanks again :100:

goeh commented 3 years ago

See https://github.com/goeh/weather-collector/blob/master/src/main/java/se/technipelago/weather/vantagepro/DownloadController.java#L83

It could probably be simplified (and better) with:

Properties properties = new Properties();
try (InputStream is = this.getClass().getResourceAsStream("datastore.properties")) {
    properties.load(is);
}