GithubHelp home page GithubHelp logo

Comments (10)

majst01 avatar majst01 commented on June 29, 2024

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.
I dont see how we could change this behaviour in a way you will get informed about write errors.

Any hints welcome
Stefan

from influxdb-java.

drb-digital avatar drb-digital commented on June 29, 2024

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);

    }

from influxdb-java.

majst01 avatar majst01 commented on June 29, 2024

Hi,
do you have any special requirements to the content of the lineprotocol which are not fulfilled with the implementation present in Point.java ? If yes please describe these and i will try to implement. Otherwise i want to keep the API as small as possible because this keeps the implementation simple with fewer bugs.

Greetings
Stefan

from influxdb-java.

drb-digital avatar drb-digital commented on June 29, 2024

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
Dennis

from influxdb-java.

majst01 avatar majst01 commented on June 29, 2024

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.

from influxdb-java.

majst01 avatar majst01 commented on June 29, 2024

Close this ticket because there seem to be urgent demand.

from influxdb-java.

drb-digital avatar drb-digital commented on June 29, 2024

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
Dennis

from influxdb-java.

Danushka96 avatar Danushka96 commented on June 29, 2024

Hi Stefan,

Is there a way to catch the exceptions while writing to influx in batch mode in the newer versions of Influx?

from influxdb-java.

majst01 avatar majst01 commented on June 29, 2024

Yes please read the documentation carefully.

from influxdb-java.

Danushka96 avatar Danushka96 commented on June 29, 2024

Got it, Thanks @majst01

from influxdb-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.