Skip to content

Commit 044cc92

Browse files
committed
removed the deprecated taskName() method by using the new introduced as() method
1 parent 4546d04 commit 044cc92

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

java/outbox.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ Schedule cronBased = Schedule.create()
433433

434434
| Method | Description | Default |
435435
|--------|-------------|---------|
436-
| `taskName(String)` | Explicitly names the task, making it a **singleton** with **upsert** semantics (see [Named Tasks](#named-singleton-tasks)) | Event name (for scheduled tasks) |
436+
| `as(String)` | Explicitly names the task, making it a **singleton** with **upsert** semantics (see [Named Tasks](#named-singleton-tasks)) | Event name (for scheduled tasks) |
437437
| `after(Duration)` | Initial delay before first execution | `Duration.ZERO` |
438438
| `every(Duration)` | Delay between recurring executions (after each successful run) | None (single execution) |
439439
| `cron(String)` | Spring Cron Expression for recurring execution | None |
@@ -449,28 +449,28 @@ Schedule cronBased = Schedule.create()
449449

450450
All scheduled tasks (using any `Schedule` other than `Schedule.NOW`) are **singletons**. The task name determines the outbox message ID, ensuring only one active instance per name exists at any time.
451451

452-
- If an explicit `taskName` is set via `.taskName(...)`, it is used as the task name.
453-
- If no explicit `taskName` is set, the **event name** is used as the task name.
452+
- If an explicit name is set via `.as(...)`, it is used as the task name.
453+
- If no explicit name is set, the **event name** is used as the task name.
454454

455455
Re-submitting a task with the same name **replaces** the existing entry entirely — the schedule, message content, and execution timestamp are all updated to reflect the latest submission. This follows **last-write-wins** semantics.
456456

457457
```java
458458
// Only one "daily-cleanup" task will exist, regardless of how often this code runs
459459
Schedule cleanup = Schedule.create()
460-
.taskName("daily-cleanup")
460+
.as("daily-cleanup")
461461
.cron("0 0 2 * * *"); // daily at 2 AM
462462
```
463463

464464
```java
465465
// Initial submission: run every hour
466466
Schedule hourly = Schedule.create()
467-
.taskName("sync-job")
467+
.as("sync-job")
468468
.every(Duration.ofHours(1));
469469
outboxService.submit("sync/trigger", message0, hourly);
470470
471471
// Later: change to every 30 minutes — replaces the existing "sync-job"
472472
Schedule every30Min = Schedule.create()
473-
.taskName("sync-job")
473+
.as("sync-job")
474474
.every(Duration.ofMinutes(30));
475475
outboxService.submit("sync/trigger", message1, every30Min);
476476
@@ -482,7 +482,7 @@ outboxService.submit("sync/trigger", message1, every30Min);
482482
The upsert mechanism is safe for concurrent submissions. If a named task is re-submitted while it is currently being processed, the new submission is preserved and will be executed according to the updated schedule after the current execution completes.
483483

484484
::: warning
485-
If you need multiple independent tasks for the same event (e.g., per-user reminders), you **must** set an explicit `taskName` to distinguish them. Without it, all submissions for the same event share one task name and re-submissions replace the existing task.
485+
If you need multiple independent tasks for the same event (e.g., per-user reminders), you **must** set an explicit name via `.as(...)` to distinguish them. Without it, all submissions for the same event share one task name and re-submissions replace the existing task.
486486
:::
487487

488488

@@ -493,14 +493,14 @@ Named tasks can be cancelled:
493493

494494
```java
495495
Schedule cancelCleanup = Schedule.create()
496-
.taskName("daily-cleanup")
496+
.as("daily-cleanup")
497497
.cancel();
498498
499499
// Submit the cancellation
500500
outboxService.submit("maintenance/cleanup", null, cancelCleanup);
501501
```
502502

503-
If no explicit `taskName` is set, the event name is used to identify the task to cancel:
503+
If no explicit name is set via `.as(...)`, the event name is used to identify the task to cancel:
504504

505505
```java
506506
Schedule cancel = Schedule.create()
@@ -522,7 +522,7 @@ When a cancellation is submitted, the named task is **deleted** from the outbox
522522
| Currently running execution | **Completes** — not interrupted |
523523
| At most one additional execution | Possible if the task was already picked up for processing |
524524
| Cancelling a non-existent task | Silent no-op (no error thrown) |
525-
| Cancellation without explicit `taskName` | Cancels the task identified by the event name |
525+
| Cancellation without explicit name | Cancels the task identified by the event name |
526526

527527

528528
#### Cron Expression Syntax
@@ -615,7 +615,7 @@ private MessagingService messagingService;
615615
616616
public void setupRecurringSync() {
617617
Schedule every10Min = Schedule.create()
618-
.taskName("data-sync")
618+
.as("data-sync")
619619
.every(Duration.ofMinutes(10));
620620
621621
MessagingService scheduled = Schedulable.of(messagingService, outboxService)
@@ -631,7 +631,7 @@ public void setupRecurringSync() {
631631
```java
632632
public void scheduleReminder(String userId) {
633633
Schedule in24Hours = Schedule.create()
634-
.taskName("reminder-" + userId) // explicit name ensures one task per user
634+
.as("reminder-" + userId) // explicit name ensures one task per user
635635
.after(Duration.ofHours(24));
636636
637637
MessagingService scheduled = Schedulable.of(messagingService, outboxService)
@@ -647,7 +647,7 @@ public void scheduleReminder(String userId) {
647647
```java
648648
public void setupDailyReport() {
649649
Schedule dailyAt6AM = Schedule.create()
650-
.taskName("daily-report")
650+
.as("daily-report")
651651
.cron("0 0 6 * * *");
652652
653653
MessagingService scheduled = Schedulable.of(messagingService, outboxService)
@@ -662,7 +662,7 @@ public void setupDailyReport() {
662662
```java
663663
public void stopDailyReport() {
664664
Schedule cancel = Schedule.create()
665-
.taskName("daily-report")
665+
.as("daily-report")
666666
.cancel();
667667
668668
// Submit the cancellation through the outbox
@@ -679,7 +679,7 @@ public void submitScheduledMessage() {
679679
OutboxMessage message = createOutboxMessage();
680680
681681
Schedule schedule = Schedule.create()
682-
.taskName("cleanup-job")
682+
.as("cleanup-job")
683683
.after(Duration.ofMinutes(5))
684684
.every(Duration.ofHours(1));
685685

0 commit comments

Comments
 (0)