我看一个 web 项目里
用 @Transactional ( readOnly = true )注解了一个类 类的方法是进行 redis/kafka 的消息发布
这个类里面就一个方法,方法的主要代码段如下:
for (String jsonStr : strArray) {
redisTemplate.convertAndSend("topic_id", jsonStr );
KafkaProducerUtil.sendMessage("topic_id", jsonStr );
}
我的疑惑是
1 这个 readOnly = true 对 redis/kafka 消息的发布有何作用?
2 这个方法里面没有抛异常的,只是 sendMessage ()的定义(定义在另一个类中)里有抛异常,但是异常在那里捕捉了,这样这个方法就没有抛异常的可能,那么加 @Transactional 注解有何用?