Java client api 3.6.0 issue


#1

Hi

I am trying out the datasift demo version using java client library version 3.6.0 for live streaming .

It doesnt shows any error , but no streaming is happenening and the program stops there . Here I am attaching my sample code

  {
  DataSiftConfig config = new DataSiftConfig(userName,apiKey);
   final DataSiftClient datasift = new DataSiftClient(config);
  
    datasift.liveStream().onError(new ErrorHandler()); 
    datasift.liveStream().onStreamEvent(new ExampleStreamEventHandler()); 

    datasift.liveStream().subscribe(new Subscription(Stream.fromString("hash")));

}

// Subscription handler
public static class Subscription extends StreamSubscription {
public Subscription(Stream stream) {
super(stream);
System.out.println(" streaming INTERACTION:\n" );
}

    public void onDataSiftLogMessage(DataSiftMessage di) {
        System.out.println((di.isError() ? "Error" : di.isInfo() ? "Info" : "Warning") + ":\n" + di);
    }

    public void onMessage(Interaction i) {
        System.out.println("INTERACTION:\n" + i);
    }
}

And I could get the data using curl https://stream.datasift.com/hash -H ‘Auth: :**’ . Is there anything i am missing ?
Thanks
Simi


#2

Hello Simi,

I’m an Engineering Manager here and I’ve spoken to the engineer who maintains the Java Client Library. Basically the live stream feature in datasift-java runs on a daemon thread, if all other threads on the JVM exit the JVM will exit. You’ll want to keep your main thread open, either by putting a web server or something on it, or for simple usage by calling System.in.read() to hold the main thread open until you hit enter.

I hope this helps you. Let me know if you have any further questions.

Thank you

Ollie Parsley


#3

Hello Ollie
Thanks for your reply and this surely helped me . I will try it out the java client lib as you suggested

Simi