如何在Spring集成项目中实现分析?

时间:2015-04-09 20:19:15

标签: java spring spring-integration

我正在开发Spring Integration Project,我想实现分析。基本思想是捕获所有网关中调用的方法名称,时间戳和次数。

是否有可用于记录这些详细信息的默认包/类?

在我继续进行之前,这是我想要做的事情,需要提出建议

  

步骤1:添加方法名称是网关方法标题

<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);
}}

1 个答案:

答案 0 :(得分:0)

你的步骤看起来很好。 但是,为什么不让Analytics Service使用@Async(在spring中使用任务执行程序服务),从而不会消耗父线程的负载。