package com.qcloud.biz;
import com.qcloud.dts.context.NetworkEnv;
import com.qcloud.dts.context.SubscribeContext;
import com.qcloud.dts.message.ClusterMessage;
import com.qcloud.dts.message.DataMessage;
import com.qcloud.dts.subscribe.ClusterListener;
import com.qcloud.dts.subscribe.DefaultSubscribeClient;
import com.qcloud.dts.subscribe.SubscribeClient;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
SubscribeContext context=new SubscribeContext();
context.setSecretId("AKID-522dabxxxxxxxxxxxxxxxxxx");
context.setSecretKey("AKEY-0ff4cxxxxxxxxxxxxxxxxxxxx");
context.setRegion("ap-chongqing");
SubscribeClient client=new DefaultSubscribeClient(context);
ClusterListener listener= new ClusterListener() {
@Override
public void notify(List<ClusterMessage> messages) throws Exception {
for(ClusterMessage m:messages){
for(DataMessage.Record.Field f:m.getRecord().getFieldList()){
if(f.getFieldname().equals("id")){
System.out.println("seq:"+f.getValue());
}
DataMessage.Record record = m.getRecord();
}
m.ackAsConsumed();
}
}
@Override
public void onException(Exception e){
System.out.println("listen exception"+e);
}};
client.addClusterListener(listener);
client.askForGUID("dts-channel-r0M8kKsSyRZmSxQt");
client.start();
}
}
Was this page helpful?