TOPAPI 消息通知机制
接收用户订阅消息
public class UserSubMain {
public static void main(String[] args ) throws ApiException {
String appKey="1021036310";
String appSecret="sandboxdc954ee217f6ad0ac192f436f";
String serverUrl = "http://gw.api.tbsandbox.com/router/rest";
DefaultTaobaoClient client = new DefaultTaobaoClient(serverUrl , appKey , appSecret, "xml");
IncrementCustomerPermitRequest req = new IncrementCustomerPermitRequest();
req.setStatus("all;all;all");
req.setTopics("trade;refund;item");
req.setType("get,syn,notify");
System.out.print((client.execute(req, "61017155c02b94c4f80e4611222c34f33b6076f29b063992074082786")).getBody());
}
}
监听类
import com.taobao.api.internal.stream.connect.ConnectionLifeCycleListener;
public class DefaultConnectionLifeCycleListener implements ConnectionLifeCycleListener {
public void onBeforeConnect() {
System.out.println("connect start ");
}
public void onConnect() {
System.out.println("connecting ");
}
public void onException(Throwable throwable) {
System.out.println("connecting error: " + throwable);
}
public void onConnectError(Exception e) {
System.out.println("connecting error: " + e);
}
public void onReadTimeout() {
System.out.println("connecting timeout");
}
public void onMaxReadTimeoutException() {
System.out.println("onMaxReadTimeoutException");
}
public void onSysErrorException(Exception e) {
System.out.println("onSysErrorException error: " + e);
}
}
监听类
import com.taobao.api.internal.stream.message.TopCometMessageListener;
public class DefaultTopCometMessageListener implements TopCometMessageListener{
public void onConnectMsg(String message) {
System.out.println("connecting onConnectMsg: " + message);
}
public void onHeartBeat() {}
public void onReceiveMsg(String message) {
System.out.println("connecting onReceiveMsg: " + message);
}
public void onConnectReachMaxTime() {}
public void onDiscardMsg(String message) {
System.out.println("connecting onDiscardMsg: " + message);
}
public void onServerUpgrade(String message) {
System.out.println("connecting onServerUpgrade: " + message);
}
public void onServerRehash() { }
public void onServerKickOff() { }
public void onClientKickOff() { }
public void onOtherMsg(String message) {
System.out.println("connecting onOtherMsg: " + message);
}
public void onException(Exception ex) { }
}
订阅消息
import com.taobao.api.internal.stream.Configuration;
import com.taobao.api.internal.stream.TopCometStream;
import com.taobao.api.internal.stream.TopCometStreamFactory;
public class ComentMain {
public static void main(String[] args ) {
String appKey="1021036310";
String appSecret="sandboxdc954ee217f6ad0ac192f436f";
Configuration conf = new Configuration(appKey,appSecret,null);
conf.setConnectUrl("http://stream.api.tbsandbox.com/stream");
TopCometStream stream = new TopCometStreamFactory(conf).getInstance();
stream.setConnectionListener(new DefaultConnectionLifeCycleListener());
stream.setMessageListener(new DefaultTopCometMessageListener());
stream.start();
}
}
TOPAPI 消息通知机制的更多相关文章
- HTML 5的消息通知机制
译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs HTML 5 已经被应用到W ...
- iOS开发-消息通知机制(NSNotification和NSNotificationCenter)
iOS中委托模式和消息机制基本上开发中用到的比较多,一般最开始页面传值通过委托实现的比较多,类之间的传值用到的比较多,不过委托相对来说只能是一对一,比如说页面A跳转到页面B,页面的B的值改变要映射到页 ...
- 杂谈:HTML 5的消息通知机制
译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs watermark/2/te ...
- 消息通知机制(NSNotification和NSNotificationCenter)
作者:FlyElephant 出处:http://www.cnblogs.com/xiaofeixiang iOS中委托模式和消息机制基本上开发中用到的比较多,一般最开始页面传值通过委托实现的比较多, ...
- odoo开发笔记--字段追踪,消息通知机制
odoo有着强大的消息记录.通知机制: 实际开发中,常常会有客户的需求,页面上form视图中的某些字段不允许反复修改, 假如有的用户修改了,恶意搞坏,往往容易给公司利益造成损失,或破坏,那么如何有效的 ...
- Android学习系列(7)--App消息通知机制
有人说,程序员很安静,但我不完全同意,程序员的聒噪,是藏在代码后面,是藏在程序后面.这篇文章是Android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. 1.消息推送机制 ...
- MVVMLight消息通知实现机制详解(一)
最近对委托.事件的订阅使用的太多,订阅与被订阅之间的绑定约束非常...麻烦,所以翻了下MVVMLight源码找出这段可以拿出来用的部分,详情见下: 一.开发中遇到的问题: 场景1:ClassA中存在事 ...
- java多线程系列(三)---等待通知机制
等待通知机制 前言:本系列将从零开始讲解java多线程相关的技术,内容参考于<java多线程核心技术>与<java并发编程实战>等相关资料,希望站在巨人的肩膀上,再通过我的理解 ...
- 使用 MVVMLight 消息通知
欢迎阅读我的MVVMLight教程系列文章<关于 MVVMLight 设计模式系列> 在文章的其实我们就说了,MVVMLight的精华就是消息通知机制,设计的非常不错.这个东西在MVVML ...
随机推荐
- 关于location.href几种用法的区别
常见的几种开发形式: self.location.href; window.location.href; this.location.href; location.href; parent.locat ...
- hdu 4325 树状数组+离散化
思路:这题的思路很容易想到,把所有时间点离散化,然后按时间一步一步来,当到达时间i的时候处理所有在i处的查询. 这个代码怎一个挫字了得 #include<iostream> #includ ...
- 实现TableLayout布局下循环取出TableRow控件中的文字内容到list集合
布局方式为TableLayout,利于实现表单样式展现. <!-- 详情内容区域 --> <ScrollView android:layout_above="@id/id_ ...
- 模板引擎逻辑语句处理之对单层for循环的处理
先上代码 private function moldforExt(){//模板单层For循环处理 $SQL=$this->sql_obj; $URL=$this->url_obj; req ...
- Excel日期格式单元格写成yyyy.MM.dd格式将无法读取到DataTable
最近在改公司的订单系统,遇到了一个奇怪的问题.C#程序需要从Excel文件中将数据全部读取到DataTable,其中Excel文件的第一列是日期格式yyyy/MM/dd,而这一列中大部分的单元格都是按 ...
- Intent的属性介绍
在Android系统的设计中有四大组件:Activity,Service,BroadcastReceiver,ContentProvider.Intent可以被应用于ContentProvider之外 ...
- mvc中的webapi
MVC中 webapi的使用 和 在其他网站中如何来调用(MVC) 1.webapi的路由规则注册在App_Start\WebApiConfig.cs文件中 2.webapi控制器继承父类 apiCo ...
- error LNK2005: DDX_Control 已经在 uafxcwd.lib(wincore2.obj) 中定义
编译错误提示: 1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "void __stdcall DDX_Control(classCData ...
- ios Swift 之github
1. 软件类 a) 作者集合 http://nondot.org/sabre/ b) swift for facebook SWIFT是一个易于使用的,基于注解的Java来创建勤俭节约序列化类型和服务 ...
- 机器学习 —— 决策树及其集成算法(Bagging、随机森林、Boosting)
本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 决策树--------------------------------------------- ...