为什么我在DEBUG中,事务提交为空?

时间:2019-12-30 21:59:39

标签: spring-boot jms activemq

我使用Spring Boot设置了JMS ActiveMQ,但是在部署应用程序时,我收到以下消息,这些消息不会停止。

2019-12-30 22:29:04.005 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:2 Transaction Commit :null
2019-12-30 22:29:04.006 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:4 Transaction Commit :null
2019-12-30 22:29:04.006 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:10 Transaction Commit :null
2019-12-30 22:29:04.006 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:3 Transaction Commit :null
2019-12-30 22:29:04.007 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:9 Transaction Commit :null
2019-12-30 22:29:04.007 DEBUG 1318 --- [enerContainer-1] o.a.a.ActiveMQSession                    : ID:N-DIGI-35299-1577740804450-1:1:5 Transaction Commit :null

以下是我申请的主要相关代码:

application.properties

spring.activemq.broker-url=failover://tcp://localhost:61616
spring.activemq.user=admin
spring.activemq.password=admin
spring.activemq.pool.enabled=true
spring.activemq.pool.configuration.max-connections=16
spring.activemq.pool.idleTimeout=512
spring.activemq.pool.expiryTimeout=4096

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
    <groupId>org.messaginghub</groupId>
    <artifactId>pooled-jms</artifactId>
</dependency>

FeedbackJms.java (即接收方):

@Component
@EnableJms
public class FeedbackJms {
    private static final Logger logger = LoggerFactory.getLogger(FeedbackJms.class);

    @Autowired
    private FeedbackService feedbackService;

    private CountDownLatch latch = new CountDownLatch(1);

    public CountDownLatch getLatch() {
        return latch;
    }

    @JmsListener(destination = "${spring.activemq.mq.feedback.insert}")
    public void recordFeedback(String feedback) {
        logger.debug("received feedback = '{}' ", feedback);
        Feedback mFeedback;
        ObjectMapper mapper = new ObjectMapper();
        // TO IGNORE UNKNOWN PROPERTIES
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.findAndRegisterModules();
        try{
            mFeedback = mapper.readValue(feedback, Feedback.class);
            mFeedback.setDatetime(LocalDateTime.now());
            feedbackService.addFeedback(mFeedback);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        latch.countDown();
    }
}

发件人

@Autowired
private JmsTemplate jmsTemplate;

@Override
public void addFeedbackMQ(String feedback) {
    logger.debug("recording feedback='{}'", feedback);
    jmsTemplate.convertAndSend(MQ_FEEDBACK_INSERT, feedback);
}

1 个答案:

答案 0 :(得分:1)

需要在log4j.properties中配置activemq的日志级别:

log4j.logger.org.apache.activemq=INFO
log4j.logger.org.apache.activemq.spring=WARN

https://activemq.apache.org/how-can-i-enable-detailed-logging