Showing
1 changed file
with
34 additions
and
34 deletions
1 | -package com.yoho.unions.server.mqconsumer; | ||
2 | - | ||
3 | -import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
4 | -import org.slf4j.Logger; | ||
5 | -import org.slf4j.LoggerFactory; | ||
6 | -import org.springframework.http.HttpHeaders; | ||
7 | -import org.springframework.http.MediaType; | ||
8 | -import org.springframework.kafka.listener.MessageListener; | ||
9 | -/** | ||
10 | - * Created by yoho on 2017/4/17. | ||
11 | - */ | ||
12 | -public class KafkaConsumer implements MessageListener<String, String> { | ||
13 | - | ||
14 | - private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class); | ||
15 | - | ||
16 | - /** | ||
17 | - * 初始化 | ||
18 | - */ | ||
19 | -// public void init(){ | ||
20 | -// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); | ||
21 | -// gdt_Headers = new HttpHeaders(); | ||
22 | -// gdt_Headers.setContentType(type); | 1 | +//package com.yoho.unions.server.mqconsumer; |
2 | +// | ||
3 | +//import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
4 | +//import org.slf4j.Logger; | ||
5 | +//import org.slf4j.LoggerFactory; | ||
6 | +//import org.springframework.http.HttpHeaders; | ||
7 | +//import org.springframework.http.MediaType; | ||
8 | +//import org.springframework.kafka.listener.MessageListener; | ||
9 | +///** | ||
10 | +// * Created by yoho on 2017/4/17. | ||
11 | +// */ | ||
12 | +//public class KafkaConsumer implements MessageListener<String, String> { | ||
13 | +// | ||
14 | +// private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class); | ||
15 | +// | ||
16 | +// /** | ||
17 | +// * 初始化 | ||
18 | +// */ | ||
19 | +//// public void init(){ | ||
20 | +//// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); | ||
21 | +//// gdt_Headers = new HttpHeaders(); | ||
22 | +//// gdt_Headers.setContentType(type); | ||
23 | +//// | ||
24 | +//// dmp_Headers = new HttpHeaders(); | ||
25 | +//// //360DMP必须强制指定,不然报如下错误 | ||
26 | +//// //org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.String] and content type [application/octet-stream] | ||
27 | +//// dmp_Headers.setContentType(type); | ||
28 | +//// dmp_Headers.add("Accept", MediaType.APPLICATION_JSON.toString()); | ||
29 | +//// dmp_Headers.add("App-Key", configReader.getString(DataToContants.DMP_UPLOAD_APP_KEY, DataToContants.DMP_UPLOAD_APP_KEY_DEFAULT)); | ||
30 | +//// } | ||
31 | +// | ||
32 | +// public void onMessage(ConsumerRecord<String, String> consumerRecord){ | ||
33 | +// logger.info("KafkaConsumer request is {}",consumerRecord); | ||
23 | // | 34 | // |
24 | -// dmp_Headers = new HttpHeaders(); | ||
25 | -// //360DMP必须强制指定,不然报如下错误 | ||
26 | -// //org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.String] and content type [application/octet-stream] | ||
27 | -// dmp_Headers.setContentType(type); | ||
28 | -// dmp_Headers.add("Accept", MediaType.APPLICATION_JSON.toString()); | ||
29 | -// dmp_Headers.add("App-Key", configReader.getString(DataToContants.DMP_UPLOAD_APP_KEY, DataToContants.DMP_UPLOAD_APP_KEY_DEFAULT)); | ||
30 | // } | 35 | // } |
31 | - | ||
32 | - public void onMessage(ConsumerRecord<String, String> consumerRecord){ | ||
33 | - logger.info("KafkaConsumer request is {}",consumerRecord); | ||
34 | - | ||
35 | - } | ||
36 | -} | 36 | +//} |
-
Please register or login to post a comment