重试选项示例在Cadence Java客户端中的用法:

huangapple go评论94阅读模式
英文:

Retry Option Example in Cadence for java client

问题

我正在寻找Java中Cadence的重试选项示例,例如,我尝试下面的代码片段,但似乎活动没有重新尝试。

```java
@ActivityMethod(scheduleToCloseTimeoutSeconds = 30)
@MethodRetry(maximumAttempts = 2, initialIntervalSeconds = 1, expirationSeconds = 30, maximumIntervalSeconds = 30)
String getGreetingContentOverTheWeb(URL url) throws IOException;

对于上面的活动,我期望如果它失败,应该自动重新尝试,下面是我如何调用它的方式。

@Override
public String getGreeting(String name) {
	// 这是一个阻塞调用,在活动完成后才返回。
	try {
		String content = activities.getGreetingContentOverTheWeb(new URL("http://localhost:3000/import-map/books"));
		return activities.composeGreeting(content, name);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return activities.composeGreeting("Hello", name);
	
}

请告诉我这里是否有任何不正确的地方,

以下是前端的快照

![enter image description here][1]


[1]: https://i.stack.imgur.com/chpxp.png

<details>
<summary>英文:</summary>

I am looking for retry option example for cadence in java, for example I am trying below code snippet but it seems the activity is not re-tried

@ActivityMethod(scheduleToCloseTimeoutSeconds = 30)
@MethodRetry(maximumAttempts = 2, initialIntervalSeconds = 1, expirationSeconds = 30, maximumIntervalSeconds = 30)
String getGreetingContentOverTheWeb(URL url) throws IOException;


for the above activity I am expecting that if it fails should be re-tried automatically, below is how I am calling it

@Override
public String getGreeting(String name) {
// This is a blocking call that returns only after the activity has completed.
try {
String content = activities.getGreetingContentOverTheWeb(new URL("http://localhost:3000/import-map/books"));
return activities.composeGreeting(content, name);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return activities.composeGreeting("Hello", name);

}


Please let me know if I am doing anything incorrect here,

Below is the snapshot from the frontend

![enter image description here][1]


  [1]: https://i.stack.imgur.com/chpxp.png

</details>


# 答案1
**得分**: 1

从事件历史中看,看起来活动已经重试了。我是通过查看 `ActivityTaskStarted.attempt` 字段来确定的。那里的数字等于重试的次数。所以根据指定的重试策略,活动被执行了两次。

我知道这个名称非常令人困惑,因为尝试应该从1开始,而不是从0开始。我们已经在我团队维护的 [temporal.io][2] Cadence 分支中进行了修复。

[1]: https://github.com/temporalio/temporal/pull/554
[2]: https://www.temporal.io/

<details>
<summary>英文:</summary>

From the event history, it looks like the activity is retried. I determined it by looking at the `ActivityTaskStarted.attempt` field. The number there is equal to the number of retries. So activity executed exactly two times as requested per the specified retry policy.

I know that the name is super confusing as attempts should start from 1 and not from 0. We already [fixed this][1] in the [temporal.io][2] Cadence fork my team maintains.


  [1]: https://github.com/temporalio/temporal/pull/554
  [2]: https://www.temporal.io/

</details>



huangapple
  • 本文由 发表于 2020年8月1日 17:09:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63203556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定