我的Android应用程序的不同Hoomescreen小部件有一个配置活动.
我在Configuration Activity中得到了WidgetId,如下所示:
widgetid = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
Run Code Online (Sandbox Code Playgroud)
但是后来在代码中我想知道哪个WidgetProvider类调用了Configuration Activity.我怎样才能做到这一点?
PS
我找到了答案:
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
AppWidgetProviderInfo appWidgetManager.getAppWidgetInfo(widgetid);
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种测试Kafka Streams应用程序的方法.这样我就可以定义输入事件,测试套件会显示输出.
没有真正的Kafka设置,这可能吗?
我尝试使用Kafka Stream将带有String / JSON消息的主题转换为Avro消息的另一个主题。
流主要方法:
streamsConfiguration.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, GenericAvroSerde.class);
final KStreamBuilder builder = new KStreamBuilder();
final Serde<String> stringSerde = Serdes.String();
builder.stream(stringSerde, stringSerde, "testin")
.mapValues(value -> AvroUtil.transform(value))
.to("testout");
final KafkaStreams streams = new KafkaStreams(builder, streamsConfiguration);
streams.start();
Run Code Online (Sandbox Code Playgroud)
转型:
public static GenericRecord transform(Object value) {
// ... parse string/json and generate Avro object
String userSchema = "{\"type\":\"record\"," +
"\"name\":\"myrecord\"," +
"\"fields\":[{\"name\":\"f1\",\"type\":\"string\"}]}";
Schema.Parser parser = new Schema.Parser();
Schema schema = parser.parse(userSchema);
GenericRecord avroRecord = new GenericData.Record(schema);
avroRecord.put("f1", "value1");
return avroRecord;
}
Run Code Online (Sandbox Code Playgroud)
并得到这样的异常:
Exception in …
Run Code Online (Sandbox Code Playgroud) 我使用Kafka进行消息队列/处理。我的问题是关于绩效/最佳实践。我将进行自己的性能测试,但也许有人已经有了结果/经验。
数据是Kafka(0.10)主题中的原始数据,我想将其结构化地传输到ES和HDFS。
现在我看到了两种可能性:
如果没有任何测试,我会说第二种选择更好/更清洁且更可靠?
elasticsearch apache-kafka logstash apache-kafka-streams apache-kafka-connect
我遇到了在节点重启后我的 Kafka Connect 工作器配置丢失的问题。( http://broker:port/connectors/ -> 空数组)
现在我认为它可能与“retention.ms”配置有关。因为connect config也存放在“config.storage.topic”中,会在“retention.ms”后删除?所以我必须设置一个非常高的“retention.ms”。这是正确的还是由Kafka自动管理?(如果您自己创建主题)
另外两个主题如何:status.storage.topic - 仅当前状态信息,不那么重要?offset.storage.topic
我有多个盐状态和命令,在其他作业当前可以运行时执行。
然后我收到新作业的错误,例如:
函数“state.apply”以 PID 3869 运行,并于 2017 年 3 月 23 日 10:19:32.691177 启动,jid 20170323101932691177
有没有办法等待其他作业先完成或并行运行作业?
我试图以avro格式消费Kafka消息,但我无法解码Go中从avro到json的消息.
我正在使用Confluent平台(3.0.1).例如,我生成avro消息,如:
kafka-avro-console-producer --broker-list localhost:9092 --topic test --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'
{"f1":"message1"}
{"f1":"message2"}
Run Code Online (Sandbox Code Playgroud)
现在我用go Kafka libary:sarama消费消息.纯文本消息正常工作.必须解码Avro消息.我发现了不同的库:github.com/linkedin/goavro,github.com/elodina/go-avro
但解码后我得到一个没有值的json(两个libs):
{"f1":""}
Run Code Online (Sandbox Code Playgroud)
goavro:
avroSchema := `
{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}
`
codec, err := goavro.NewCodec(avroSchema)
if err != nil {
log.Fatal(err)
}
bb := bytes.NewBuffer(msg.Value)
decoded, err := codec.Decode(bb)
log.Println(fmt.Sprintf("%s", decoded))
Run Code Online (Sandbox Code Playgroud)
去-Avro公司:
schema := avro.MustParseSchema(avroSchema)
reader := avro.NewGenericDatumReader()
reader.SetSchema(schema)
decoder := avro.NewBinaryDecoder(msg.Value)
decodedRecord := avro.NewGenericRecord(schema)
log.Println(decodedRecord.String())
Run Code Online (Sandbox Code Playgroud)
msg = sarama.ConsumerMessage