|
|
package com.yoho.unions.server.mqconsumer;
|
|
|
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.kafka.listener.MessageListener;
|
|
|
/**
|
|
|
* Created by yoho on 2017/4/17.
|
|
|
*/
|
|
|
public class KafkaConsumer implements MessageListener<String, String> {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);
|
|
|
|
|
|
/**
|
|
|
* 初始化
|
|
|
*/
|
|
|
// public void init(){
|
|
|
// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
// gdt_Headers = new HttpHeaders();
|
|
|
// gdt_Headers.setContentType(type);
|
|
|
//package com.yoho.unions.server.mqconsumer;
|
|
|
//
|
|
|
//import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
//import org.slf4j.Logger;
|
|
|
//import org.slf4j.LoggerFactory;
|
|
|
//import org.springframework.http.HttpHeaders;
|
|
|
//import org.springframework.http.MediaType;
|
|
|
//import org.springframework.kafka.listener.MessageListener;
|
|
|
///**
|
|
|
// * Created by yoho on 2017/4/17.
|
|
|
// */
|
|
|
//public class KafkaConsumer implements MessageListener<String, String> {
|
|
|
//
|
|
|
// private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);
|
|
|
//
|
|
|
// /**
|
|
|
// * 初始化
|
|
|
// */
|
|
|
//// public void init(){
|
|
|
//// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
//// gdt_Headers = new HttpHeaders();
|
|
|
//// gdt_Headers.setContentType(type);
|
|
|
////
|
|
|
//// dmp_Headers = new HttpHeaders();
|
|
|
//// //360DMP必须强制指定,不然报如下错误
|
|
|
//// //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]
|
|
|
//// dmp_Headers.setContentType(type);
|
|
|
//// dmp_Headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
//// dmp_Headers.add("App-Key", configReader.getString(DataToContants.DMP_UPLOAD_APP_KEY, DataToContants.DMP_UPLOAD_APP_KEY_DEFAULT));
|
|
|
//// }
|
|
|
//
|
|
|
// public void onMessage(ConsumerRecord<String, String> consumerRecord){
|
|
|
// logger.info("KafkaConsumer request is {}",consumerRecord);
|
|
|
//
|
|
|
// dmp_Headers = new HttpHeaders();
|
|
|
// //360DMP必须强制指定,不然报如下错误
|
|
|
// //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]
|
|
|
// dmp_Headers.setContentType(type);
|
|
|
// dmp_Headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
// dmp_Headers.add("App-Key", configReader.getString(DataToContants.DMP_UPLOAD_APP_KEY, DataToContants.DMP_UPLOAD_APP_KEY_DEFAULT));
|
|
|
// }
|
|
|
|
|
|
public void onMessage(ConsumerRecord<String, String> consumerRecord){
|
|
|
logger.info("KafkaConsumer request is {}",consumerRecord);
|
|
|
|
|
|
}
|
|
|
} |
|
|
//} |
...
|
...
|
|