package com.itheima.kafka.producer.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class KFProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate ;

    @Transactional(rollbackFor = RuntimeException.class)
    public void sendTransactionMessage() {

        // 发送消息
        kafkaTemplate.send("itcast01" , 0 , "order" , "事务消息 ----> 1") ;
        kafkaTemplate.send("itcast01" , 0 , "order" , "事务消息 ----> 2") ;

        // 产生异常代码
        int a = 1 / 0 ;

        kafkaTemplate.send("itcast01" , 0 , "order" , "事务消息 ----> 3") ;

    }

}
