为了在Camel上执行性能测量和审计日志记录,AuditEventNotifer实现如下。但是,每个事件都会记录两次。例如, 31140 的消息完成事件将被记录两次。有人能给我一些关于如何解决问题的提示吗?
路线定义
from(INBOUND_ENDPOINT).filter(header("foo").isEqualTo("bar")).to(
"mock:result");
AuditEventNotifer Implementation
@Component
public class AuditEventNotifer extends EventNotifierSupport {
private static final Logger LOGGER = LoggerFactory
.getLogger(AuditEventNotifer.class);
@Override
public void notify(EventObject event) throws Exception {
LOGGER.info(event.toString());
}
以下是生成的日志
15:29:12.497 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31140]]
15:29:12.497 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31140]]
15:29:12.497 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31141]]
15:29:12.497 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31141]]
15:29:12.498 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31142]]
15:29:12.498 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31142]]
15:29:12.498 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31143]]
15:29:12.498 [thread #0 - JmsConsumer[ticket_queue]] INFO AuditEventNotifer:19 - exchange completed: Exchange[JmsMessage[JmsMessageID: ID:fe80:0:0:0:be30:5bff:feee:6a24%em1a48e14979b5068a0:31143]]
答案 0 :(得分:0)
检查通知程序bean是否未配置两次。如果该类使用@Component
注释,那么bean必须在Spring XML配置中定义 :
<bean id="auditEventNotifier" class="your.package.AuditEventNotifer" />
选择一种或另一种可能性,但不是两种。
答案 1 :(得分:0)
由于您没有覆盖
public boolean isEnabled(EventObject event)
它为每个事件状态打印消息。
例如:如果您希望邮件在发送时仅打印一次,请检查下面的代码块。
@Component
public class AuditEventNotifer extends EventNotifierSupport {
private static final Logger LOGGER = LoggerFactory
.getLogger(AuditEventNotifer.class);
@Override
public boolean isEnabled(EventObject event) {
return event instanceof ExchangeSentEvent;
}
@Override
public void notify(EventObject event) throws Exception {
LOGGER.info(event.toString());
}
}