使用Android应用程序作为Apache Kafka的"制作客户端"是否可行/是否有意义?
假设我的Android App需要捕获和分析反应时间数据.目标是收集所有数据并在App中实时显示平均反应时间.
另一种方法是让某个应用程序服务器作为中间人接受来自Android应用程序的消息并将其发布到Kafka,而不是让应用程序自己成为Kafka Producer.
我正在研究应该通过kafka写入hdfs的项目.假设有在线服务器将消息写入kafka.每条消息都包含时间戳.我想根据消息中的时间戳创建一个输出将是文件/文件的作业.例如,如果kafka中的数据是
{"ts":"01-07-2013 15:25:35.994", "data": ...}
...
{"ts":"01-07-2013 16:25:35.994", "data": ...}
...
{"ts":"01-07-2013 17:25:35.994", "data": ...}
Run Code Online (Sandbox Code Playgroud)
我想得到3个文件作为输出
kafka_file_2013-07-01_15.json
kafka_file_2013-07-01_16.json
kafka_file_2013-07-01_17.json
Run Code Online (Sandbox Code Playgroud)
当然,如果我再次运行这个工作,并且有一个新的消息在队列中
{"ts":"01-07-2013 17:25:35.994", "data": ...}
Run Code Online (Sandbox Code Playgroud)
它应该创建一个文件
kafka_file_2013-07-01_17_2.json // second chunk of hour 17
Run Code Online (Sandbox Code Playgroud)
我见过一些开源,但大多数都是从kafka读到一些hdfs文件夹.这个问题的最佳解决方案/设计/开源是什么?
谁能解释我如何在 Android 中使用 ElasticSearch API。有没有人成功地将 api 集成到 android 中?
我在 Gradle 中添加了以下依赖项:
compile 'org.elasticsearch.client:transport:5.2.1'
Run Code Online (Sandbox Code Playgroud)
当然,我遇到了问题:
错误:任务“:app:transformResourcesWithMergeJavaResForDebug”的执行失败。com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在 APK META-INF/LICENSE File1 中复制的重复文件:C:\Users\dude.gradle\caches\modules-2\files -2.1\org.apache.httpcomponents\httpcore-nio\4.4.5\f4be009e7505f6ceddf21e7960c759f413f15056\httpcore-nio-4.4.5.jar File2: C:\Users\dude.gradle\caches\file-orgs-2 .apache.httpcomponents\httpasyncclient\4.1.2\95aa3e6fb520191a0970a73cf09f62948ee614be\httpasyncclient-4.1.2.jar File3:C:\Users\dude.gradle\caches\modules-2\xml.jackson.data. -dataformat-yaml\2.8.6\8bd44d50f9a6cdff9c7578ea39d524eb519e35ab\jackson-dataformat-yaml-2.8.6.jar File4: C:\Users\dude.gradle\caches\modules-2\files-2.1\org.
.
更新1:
好吧,我必须使用使用REST API的Android异步HTTP客户端,因为加入packagingOptions并没有解决问题
是否可以设置requestReport的日期范围?
POST /v2/sp/{recordType}/report
{
"segment": {segment},
"reportDate": {reportDate}, <-- here
"metrics": {metrics}
}
Run Code Online (Sandbox Code Playgroud)
还是我需要提出30个请求才能获得一个月的结果?也许快照可以帮助?
我试着花时间System.currentTimeMillis(),而不是用户按下媒体按钮.但回调是在媒体按钮再次上升时执行的action == KeyEvent.ACTION_UP.
我不想在我的解决方案中使用BroadcastReceiver.
这是我的代码:
MediaSession audioSession = new MediaSession(getApplicationContext(), "TAG");
audioSession.setCallback(new MediaSession.Callback() {
@Override
public boolean onMediaButtonEvent(final Intent mediaButtonIntent) {
String intentAction = mediaButtonIntent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
{
KeyEvent event = (KeyEvent)mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null)
{
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
long stopTimeOfGame_millis = System.currentTimeMillis();
UtilsRG.info("time stopped: " +stopTimeOfGame_millis);
}
if (action == KeyEvent.ACTION_UP) {
long test = System.currentTimeMillis();
UtilsRG.info("time stopped up: " +test);
}
}
}
return super.onMediaButtonEvent(mediaButtonIntent);
}
}); …Run Code Online (Sandbox Code Playgroud)