package com.copy.trade.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.copy.trade.entity.po.Message;
import com.copy.trade.service.IMessageService;

@Component
public class MessagePushConsumer {
	
	@Autowired
	private IMessageService messageServiceImpl;

	@KafkaListener(topics = {"follow-message-push"},containerFactory = "ackContainerFactory")
    public void onMessagePush(ConsumerRecord<String, String> record, Acknowledgment ack){
		Message message = JSON.parseObject(record.value(), Message.class);
		messageServiceImpl.saveMessage(message);
		
		ack.acknowledge();
	}
}
