How to use TDengine's subscribe function to subscribe data

Viewed 26

I want to use tdengine's subscribe function to subscribe an class of equipments' data which in fact is a super table. I Just follow the demo in their offical website. Since I want resume consume,the data I hasn't consumed. The Code is like bellow:

//CREATE SUBSCRIBE
TSDBSubscribe sub = ((TSDBConnection)conn).subscribe("topic", "select * from meters", false);

//CONSUME DATA
int total = 0;
while(true) {
    TSDBResultSet rs = sub.consume();
    int count = 0;
    while(rs.next()) {
        count++;
    }
    total += count;
    System.out.printf("%d rows consumed, total %d\n", count, total);
    Thread.sleep(1000);
}

//CLOSE SUBSCRIBE 
sub.close(true);

//RELEASE RESOURCE
resultSet.close();
stmt.close();
conn.close();

This code is just the same as their website's demo code, but it didn't performance like their descriptions. I set the "restart = false" , it still consume from the beginning. i wish someone can help find out what's the wrong with this?

1 Answers
  1. I have met with this problem. At firs, you can check with your tdengine client‘s taoslog.*. You can find that there is an error which is about a path. (I forgot the actual name, but with path name include subscribe).
  2. Then you can check if the path exists, if not please create it then try.
  3. If you want to query data after last consumption, the taos client need to mark the consume progress in local machine. What's the path mention previous it where the progress will be record.
Related