【发布时间】:2015-04-09 20:19:14
【问题描述】:
我正在从事 Spring 集成项目,我想实施分析。基本思想是捕获所有网关中调用的方法名称、时间戳和次数。
是否有任何默认包/类可用于记录这些详细信息?
这是我想做的事情,在我继续之前需要建议
第一步:添加方法名是网关方法头
<int:gateway id="gateway" service-interface="org.pro.gateway.SampleGateway">
<int:method name="method1" request-channel="request.input.channel" reply-channel="reply.output.channel">
<int:header name="methodName" value="placeOrder"/>
</int:method>
</int:gateway>
第 2 步: 添加 Spring Wire tap 拦截器,应用仅匹配输入通道的模式。在窃听通道中按名称获取消息头并记录。
<int:wire-tap channel="wiretapChannel" pattern="input*" />
<int:service-activator ref="analyticsBean" method="footprint" input-channel="wiretapChannel" output-channel="outputChannel"/>
<bean id="analyticsBean" class="org.pro.stat.AnalyticService"/>
第 3 步: 实施代码
public class AnalyticsService {
public void footprint(Message<String> msg){
String methodName = msg.getHeaders().get("methodName");
long timestamp = msg.getHeaders().getTimestamp();
/* Send to some service / store it in file with incremented value */
storeIt(methodName, timestamp);
}}
【问题讨论】:
标签: java spring spring-integration