使用AWS SWF在分布式架构活动管理 [英] Activity Management in distributed architecture using AWS SWF

查看:289
本文介绍了使用AWS SWF在分布式架构活动管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个服务器(EC2实例)。在一台服务器(服务器1)我有3个批次,并在另一个(服务器2)我有4个批次。现在,只需要在服务器1中的成功执行了一批后要执行的批次在服务器2中的一个。

I have two servers(EC2 instances). In one server(server 1) i have 3 Batch and on another(server 2) i have 4 Batch. Now, one of the batch in server 2 needs to be executed only after the successful execution of a batch in server 1.

更新

    Promise<Void> r12 = null
    new TryCatchFinally(){

    // First server job sequencing
    Promise<Void> r11 = client1.b1();
    r12 = client1.b2(r11);
    Promise<Void> r13 = client1.b3(r12);
    Promise<Void> r14 = client1.b4(r13);
    }
    @Override
    protected void doCatch(Throwable e) throws Throwable {
    System.out.println("Failed to execute commands in server 1");
    }
    @Override
    protected void doFinally() throws Throwable {
    // cleanup
    }       
    }
    new TryCatchFinally(){

    // Second server job sequencing
    Promise<Void> r21 = client2.b1();
    // Will execute only when both parameters are ready
    Promise<Void> r22 = client2.b2(r21, r12);
    Promise<Void> r23 = client2.b3(r22);
    Promise<Void> r24 = client2.b4(r23);
    }
    @Override
    protected void doCatch(Throwable e) throws Throwable {
    System.out.println("Failed to execute commands in server 2");
    }
    @Override
    protected void doFinally() throws Throwable {
    // cleanup
    }       
    }

在任何服务器上的任何活动都可以抛出任何自定义异常。因为异常的另一个服务器抛出活性而任何活动在一个服务器对执行不应该被取消。在一台服务器的活动只能在案件被取消在它自己的服务器活动之一抛出任何异常。 (相关活动应该也被取消了,不论服务器,如果其所依赖的活动失败或抛出任何异常)。对于这个我所做的是把它包成两个独立的try catch块。

Any of the activity in any server can throw any custom exception. But the execution of any activity in a sever should not be cancelled because of exception thrown by activity in another server. Activity in a server should only be cancelled in case one of the activity in its own server throws any exception. (Dependent activity should also gets cancelled out irrespective of server if the activity on which it is dependent fails or throw any exception). For this what I did is wrapped it into two separate try catch block.

如何终止工作流执行,如果服务器1和服务器2都的活动引发的任何异常或失败?

how to terminate the Workflow Execution if the activity of server 1 and server 2 both throws any exception or fails?

推荐答案

您可以包装,每年春天批处理执行到SWF的活动,然后使用SWF决胜局测序这些活动。请参见 AWS流程框架文档和的食谱,获取更多信息。

You can wrap each Spring Batch execution into a SWF activity and then use SWF decider to sequence these activities. See AWS Flow Framework documentation and recipes for more info.

由读取问题的更新的描述后:

您可以使用承诺以任何方式排序活动。所以,你的情况我会做这样的事情:

You can use Promises to sequence activities in any way. So in your case I would do something like:

// First server job sequencing
Promise<Void> r11 = client1.b1();
Promise<Void> r12 = client1.b2(r11);
Promise<Void> r13 = client1.b3(r12);
Promise<Void> r14 = client1.b4(r13);

// Second server job sequencing
Promise<Void> r21 = client2.b1();
// Will execute only when both parameters are ready
Promise<Void> r22 = client2.b2(r21, r12);
Promise<Void> r23 = client2.b3(r22);
Promise<Void> r24 = client2.b4(r23);

如果任何活动抛出一个异常,将取消所有未完成的活动,但无法工作流程,除非异常明确地逮住,并办理了使用<一个href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/simpleworkflow/flow/core/TryCatchFinally.html"相对=nofollow> TryCatchFinally 。该没有启动(例如由于它正在等待型无极变成准备其参数)的活性被立即取消。正在执行应明确处理取消的活动。请参阅从<一活动心跳节href="http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/errorhandling.html#test.cancellation.resources"相对=nofollow>错误处理的 AWS流页面框架指南获取更多信息。

If any of the activities throws an exception it would cancel all outstanding activities and fail the workflow unless the exception is explicitly catched and handled using TryCatchFinally. Activity that wasn't started (for example because it is waiting for its parameters of type Promise become ready) is cancelled immediately. An activity that is executing should explicitly handle cancellation. See "Activity Heartbeat" section from Error Handling page of the AWS Flow Framework Guide for more info.

添加了错误处理的部分:

您换不应该影响到TryCatch的worklfow其他部分的一部分。因此,在这个例子中的任何客户机程序的活动抛出一个异常,将取消今后所有的客户机程序的活动,但呼吁CLIENT1没有活动异常没有扔进其范围。

You wrap the part that shouldn't affect other parts of the worklfow in the TryCatch. So in this example any client2 activity throwing an exception cancels all future client2 activities, but not activities called on client1 as exception is not thrown into its scope.

// First server job sequencing
Promise<Void> r11 = client1.b1();
final Promise<Void> r12 = client1.b2(r11);
Promise<Void> r13 = client1.b3(r12);
Promise<Void> r14 = client1.b4(r13);

new TryCatch(){

  @Override
  protected void doTry() throws Throwable {
    // Second server job sequencing
    Promise<Void> r21 = client2.b1();
    // Will execute only when both parameters are ready
    Promise<Void> r22 = client2.b2(r21, r12);
    Promise<Void> r23 = client2.b3(r22);
    Promise<Void> r24 = client2.b4(r23);
  }

  @Override
  protected void doCatch(Throwable e) throws Throwable {
    // Handle exception without rethrowing it.
  }
}

这篇关于使用AWS SWF在分布式架构活动管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆