javaspring-bootrethinkdb

How to make RethinkDB to call a java function whenever new insertion happens?


Hello all, I am new to Rethink-db can anyone help me with this as i mentioned in above query. I am creating one java service with Rethink-db so whenever new entries inserted into Rethink-db a java method should call by Rethink-db itself with data that i inserted. And is this possible to achieve it? Thanks.


Solution

  • I hope you have proper dependency set, below code may help you.

    static Connection con = r.connection().hostname("localhost").port(28015).db("db_name").connect();
    public static final RethinkDB r = RethinkDB.r;
    public static void getChangeEffect() {
        Result<Object> changes = r.table("table_name").changes().run(con);
        for (Object change : changes) {
            System.out.println(change);
        }
    
    }
    

    The above code will execute and prints all the rows whenever a new insertion takes place.