Authored by markeloff

kafka消息类型String改为byte

@@ -4,8 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -4,8 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.google.common.collect.Sets; 4 import com.google.common.collect.Sets;
5 import com.yoho.trace.handler.TraceHandlerStarter; 5 import com.yoho.trace.handler.TraceHandlerStarter;
6 import com.yoho.trace.sleuth.Spans; 6 import com.yoho.trace.sleuth.Spans;
7 -import kafka.serializer.StringDecoder;  
8 -import org.apache.commons.lang3.StringUtils; 7 +import kafka.serializer.DefaultDecoder;
9 import org.apache.spark.SparkConf; 8 import org.apache.spark.SparkConf;
10 import org.apache.spark.api.java.function.Function0; 9 import org.apache.spark.api.java.function.Function0;
11 import org.apache.spark.streaming.Durations; 10 import org.apache.spark.streaming.Durations;
@@ -55,19 +54,19 @@ public class TraceExecutor { @@ -55,19 +54,19 @@ public class TraceExecutor {
55 kafkaParamMap.put("fetch.message.max.bytes", "104857600"); 54 kafkaParamMap.put("fetch.message.max.bytes", "104857600");
56 kafkaParamMap.put("group.id", kafkaPro.getGroup()); 55 kafkaParamMap.put("group.id", kafkaPro.getGroup());
57 HashSet<String> topics = Sets.newHashSet(kafkaPro.getTopic()); 56 HashSet<String> topics = Sets.newHashSet(kafkaPro.getTopic());
58 - JavaPairInputDStream<String, String> kafkaPairInputStream = KafkaUtils.createDirectStream(streamingContext,  
59 - String.class,  
60 - String.class,  
61 - StringDecoder.class,  
62 - StringDecoder.class, 57 + JavaPairInputDStream<byte[], byte[]> kafkaPairInputStream = KafkaUtils.createDirectStream(streamingContext,
  58 + byte[].class,
  59 + byte[].class,
  60 + DefaultDecoder.class,
  61 + DefaultDecoder.class,
63 kafkaParamMap, 62 kafkaParamMap,
64 topics); 63 topics);
65 JavaDStream<Spans> kafkaMsgDStream = kafkaPairInputStream.mapPartitions(msgIterator -> { 64 JavaDStream<Spans> kafkaMsgDStream = kafkaPairInputStream.mapPartitions(msgIterator -> {
66 List<Spans> messages = new ArrayList<>(); 65 List<Spans> messages = new ArrayList<>();
67 ObjectMapper jacksonMapper = new ObjectMapper(); 66 ObjectMapper jacksonMapper = new ObjectMapper();
68 while (msgIterator.hasNext()) { 67 while (msgIterator.hasNext()) {
69 - Tuple2<String, String> msgTuple2 = msgIterator.next();  
70 - if (StringUtils.isNoneBlank(msgTuple2._2())) { 68 + Tuple2<byte[], byte[]> msgTuple2 = msgIterator.next();
  69 + if (msgTuple2._2() != null && msgTuple2._2().length > 0) {
71 Spans spans = null; 70 Spans spans = null;
72 try { 71 try {
73 spans = jacksonMapper.readValue(msgTuple2._2(), Spans.class); 72 spans = jacksonMapper.readValue(msgTuple2._2(), Spans.class);
1 package com.yoho.trace.handler; 1 package com.yoho.trace.handler;
2 2
3 import com.yoho.trace.sleuth.Spans; 3 import com.yoho.trace.sleuth.Spans;
4 -import com.yoho.trace.sleuth.TraceStoreUtils; 4 +import com.yoho.trace.sleuth.util.TraceStoreUtils;
5 import org.apache.spark.streaming.api.java.JavaDStream; 5 import org.apache.spark.streaming.api.java.JavaDStream;
6 6
7 /** 7 /**
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 package com.yoho.trace.sleuth; 17 package com.yoho.trace.sleuth;
18 18
  19 +import com.yoho.trace.sleuth.util.StringUtils;
19 import org.apache.commons.collections.CollectionUtils; 20 import org.apache.commons.collections.CollectionUtils;
20 21
21 import java.util.Collection; 22 import java.util.Collection;
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 package com.yoho.trace.sleuth; 16 package com.yoho.trace.sleuth;
17 17
  18 +import com.yoho.trace.sleuth.util.StringUtils;
18 import org.slf4j.Logger; 19 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
20 import zipkin.BinaryAnnotation; 21 import zipkin.BinaryAnnotation;
@@ -19,6 +19,7 @@ package com.yoho.trace.sleuth; @@ -19,6 +19,7 @@ package com.yoho.trace.sleuth;
19 import com.fasterxml.jackson.annotation.JsonAutoDetect; 19 import com.fasterxml.jackson.annotation.JsonAutoDetect;
20 import com.fasterxml.jackson.annotation.JsonIgnore; 20 import com.fasterxml.jackson.annotation.JsonIgnore;
21 import com.fasterxml.jackson.annotation.JsonInclude; 21 import com.fasterxml.jackson.annotation.JsonInclude;
  22 +import com.yoho.trace.sleuth.util.StringUtils;
22 23
23 import java.util.*; 24 import java.util.*;
24 import java.util.concurrent.ConcurrentHashMap; 25 import java.util.concurrent.ConcurrentHashMap;
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package com.yoho.trace.sleuth; 17 +package com.yoho.trace.sleuth.util;
18 18
19 import org.apache.commons.collections.CollectionUtils; 19 import org.apache.commons.collections.CollectionUtils;
20 20
1 -package com.yoho.trace.sleuth; 1 +package com.yoho.trace.sleuth.util;
2 2
  3 +import com.yoho.trace.sleuth.Spans;
  4 +import com.yoho.trace.sleuth.ZipkinESStoreConfiguration;
  5 +import com.yoho.trace.sleuth.ZipkinMessageListener;
3 import org.apache.commons.collections.CollectionUtils; 6 import org.apache.commons.collections.CollectionUtils;
4 7
5 /** 8 /**