You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
764 B

package com.java3y.austin.kafkatest;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
/**
* @Author 18011618
* @Description
* @Date 14:43 2018/7/20
* @Modify By
*/
@Component
public class UserLogProducer {
@Autowired
private KafkaTemplate kafkaTemplate;
/**
* 发送数据
* @param userid
*/
public void sendLog(String userid){
UserLog userLog = new UserLog();
userLog.setUsername("jhp").setUserid(userid).setState("0");
System.err.println("发送用户日志数据:"+userLog);
kafkaTemplate.send("austin", JSON.toJSONString(userLog));
}
}