-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result of influxDB#write() #47
Comments
Hi Dennis, the write is as long as you did not enable batchMode a synchronous call which will throw a RuntimeException if something went wrong, so you will notice it in you app. If batchMode is enabled, this exception will be thrown in the flusher thread. Any hints welcome |
Hi Stefan, thanks for your reply. Unfortunately I am using batch mode. I'll give it some thought and let you know if I am coming any closer to a possible solution. One more thing: I am using strings containing lineProtocol to store points/batch points locally. But as far as I can see there is no method to write lineProtocol instead of points/batch points. I tried using query instead, but that wasn't working for me. So I implemented an additional method to InfluxDBImpl.java. I think this is useful for others too, so probably you could include some method like this. Dennis public void write(final String database, final String retentionPolicy, final String getLineProtocol) {
TypedString lineProtocol = new TypedString(getLineProtocol);
this.influxDBService.writePoints(
this.username,
this.password,
database,
retentionPolicy,
TimeUtil.toTimePrecision(TimeUnit.NANOSECONDS),
ConsistencyLevel.ONE.toString(),
lineProtocol);
} |
Hi, Greetings |
Hi Stefan, no, Point.java is allright. What I want to achieve is the following. My influxdb instance is running on a server, data is collected on a mobile device. Every time an exception is thrown, I am storing the point which haven't been sent to influxdb to a local SQLite database. Therefore I am using the method Point#lineProtocol(), which is working fine. try {
InfluxDB influxDB = InfluxDBFactory.connect(dbUrl, dbUser, dbPassword);
influxDB.write(dbName, dbRetentionPolicy, point);
} catch (Exception e) {
DatabaseSQLite databaseSQLite = new DatabaseSQLite();
databaseSQLite.openConnection();
databaseSQLite.insertLineProtocol(point.lineProtocol());
databaseSQLite.closeConnection();
} What I am missing is a possibility to send these stored points to influxdb after retrieving them from local database. Therefore I implemented the method mentioned in my comment above and use it as follows: DatabaseSQLite databaseSQLite = new DatabaseSQLite();
databaseSQLite.openConnection();
String lineProtocol = databaseSQLite.getLineProtocol(id);
databaseSQLite.closeConnection();
InfluxDB influxDB = InfluxDBFactory.connect(dbUrl, dbUser, dbPassword);
influxDB.write(dbName, dbRetentionPolicy, lineProtocol); Another solution would be to convert lineProtocol strings back to points, which could then be sent by the already existing API. Hope this explanation helps. Greetings |
Hi Dennis, ok got it, but why not serialize/deserialize The Point instance which failed to json and back to a instance for example with GSON: Gson gson = new Gson();
String pointAsJson = gson.toJson(point);
// persist to SQLite
Point point = gson.fromJson(pointAsJson,Point.class);
// persist in influxdb IMHO lineprotocol is not a proper serialization of points. |
Close this ticket because there seem to be urgent demand. |
Hi Stefan, sorry for the delayed reply. That was my first guess too. But when I used JSON parser by Jackson execution failed every time (I cant't remember the error message, but it was something like error while building json from Point). Therefore I was looking into the lineProtocol and didn't try GSON. I'll gave it a try now and it seems to work pretty well. Thanks for your hint! Greetings |
Hi Stefan, Is there a way to catch the exceptions while writing to influx in batch mode in the newer versions of Influx? |
Yes please read the documentation carefully. |
Got it, Thanks @majst01 |
Hi Stefan,
first of all thanks for your great work on InfluxDB implementation for java. Including your commits from the last days it is working quite well in my 0.9.0 environment.
I was wondering if there is any possibility to get the result of writing a point (or batched points) to database? Somehow like boolean true/false. I'd like to store my data locally if there is any error (e.g. no connection) and try again later.
Thanks,
Dennis
The text was updated successfully, but these errors were encountered: