如何在Akka演员中处理这种情况

时间:2019-07-24 08:00:44

标签: spring akka

我在春季项目中使用的是Akka v2.4.20,下面有一个这样的场景,试图使用akka actor来实现。

我有不同的实体数据要从正在暴露给SOAP Web服务的其他应用程序中获取。即数据源是SOAP API。

我需要构造SOAP URL并添加特定于实体的请求,点击并获取特定于实体的结果...即,需要花费一些时间从其他系统使用每个请求的url获取结果。

我有像行业这样的实体...它有几家公司。 即从我的数据库表中,我得到了这些公司...

companyIds = getCompaniesByIndustry(industryId)

for( companyId : companyIds){
     FetchActor.tell(companyId ,self())
}

@Component
@Scope("prototype")
SOAPAPI soapAPI{
  return URL; /// other componenet SOAP service
}

@Component
@Scope("prototype")
FetchActor extends UntypedActor {
   @Override
   public void preStart() throws Exception {
    //
   }
  public void onReceive(Object msg) throws Throwable {
               if(msg instanceof String) {
                   String companyId  = (String )  msg;
                   // fetch results of companyId by calling SOAP URL  ---this is causing issue here 
                   //save results in lis/db table.
  }
}

我已经在春季按如下方式配置了FetchActor。

@Bean
public ActorSystem actorSystem() {

          ActorSystem system = ActorSystem.create("ActorSystem", akkaConfiguration());
  springExtension.initialize(applicationContext);

                      system.actorOf((springExtension.props("fetchActor")).withRouter(new RoundRobinPool( 5 )), "FetchActor");


           return system;
        }

问题: 当我迭代公司...并为每个companyId调用SOAP URL时。 对于少量数据或在调试模式下,此方法很好用。

但是当我运行它时,下一个线程/迭代到..previous SOAP URL不会返回。 因此,某些迭代将无法获取数据……而某些迭代将从SOAP URL中获取数据。

即使我增加了池大小(即RoundRobinPool(20)),仍然是同样的问题。有时,在下一次迭代的公司中,有一家叫/来得早的SOAP URL的公司未返回数据...

如果在没有演员的情况下也这样做...顺序调用它会很好....那么问题出在哪里呢?如何解决此问题???

非常感谢您的解决方案。...

0 个答案:

没有答案