|
3 | 3 | package io.durabletask.samples; |
4 | 4 |
|
5 | 5 | import com.microsoft.durabletask.*; |
| 6 | +import com.microsoft.durabletask.exporthistory.client.ExportHistoryClient; |
| 7 | +import com.microsoft.durabletask.exporthistory.client.ExportHistoryClients; |
6 | 8 | import com.microsoft.durabletask.exporthistory.client.ExportHistoryWorkers; |
7 | 9 | import com.microsoft.durabletask.exporthistory.options.ExportHistoryStorageOptions; |
8 | 10 |
|
9 | 11 | import org.springframework.boot.SpringApplication; |
10 | 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 13 | +import org.springframework.context.annotation.Bean; |
11 | 14 |
|
12 | 15 | /** |
13 | 16 | * Export History sample — Spring Boot web app with REST endpoints for managing export jobs. |
14 | 17 | * <p> |
15 | 18 | * Java equivalent of the .NET ExportHistoryWebApp sample. |
16 | 19 | * <p> |
17 | 20 | * Run: ./gradlew runExportHistorySample |
18 | | - * API: http://localhost:8080/export-jobs |
| 21 | + * API: http://localhost:5009/export-jobs |
19 | 22 | * <p> |
20 | 23 | * Requires DTS emulator and Azurite (or Azure Storage). |
21 | 24 | */ |
22 | 25 | @SpringBootApplication |
23 | 26 | public class ExportHistorySample { |
24 | 27 |
|
25 | | - // Shared instances — set in main(), read by controller |
26 | | - static DurableTaskClient client; |
27 | | - static ExportHistoryStorageOptions storageOptions; |
28 | | - |
29 | 28 | public static void main(String[] args) { |
30 | | - // Config |
| 29 | + System.out.println("Export History Web App starting..."); |
| 30 | + System.out.println("REST API: http://localhost:5009/export-jobs"); |
| 31 | + |
| 32 | + // Use port 5009 to avoid conflict with DTS emulator on 8080 |
| 33 | + System.setProperty("server.port", "5009"); |
| 34 | + SpringApplication.run(ExportHistorySample.class, args); |
| 35 | + } |
| 36 | + |
| 37 | + @Bean |
| 38 | + public ExportHistoryStorageOptions storageOptions() { |
31 | 39 | String connStr = env("EXPORT_HISTORY_STORAGE_CONNECTION_STRING", "UseDevelopmentStorage=true"); |
32 | 40 | String container = env("EXPORT_HISTORY_CONTAINER_NAME", "export-history"); |
33 | | - |
34 | | - storageOptions = ExportHistoryStorageOptions.newBuilder() |
| 41 | + return ExportHistoryStorageOptions.newBuilder() |
35 | 42 | .connectionString(connStr) |
36 | 43 | .containerName(container) |
37 | 44 | .build(); |
| 45 | + } |
38 | 46 |
|
39 | | - // Client |
40 | | - client = SampleUtils.newClientBuilder().build(); |
| 47 | + @Bean |
| 48 | + public DurableTaskClient durableTaskClient() { |
| 49 | + return SampleUtils.newClientBuilder().build(); |
| 50 | + } |
41 | 51 |
|
42 | | - // Worker — registers export history entity, orchestrators, activities |
| 52 | + @Bean(destroyMethod = "stop") |
| 53 | + public DurableTaskGrpcWorker durableTaskWorker( |
| 54 | + DurableTaskClient client, ExportHistoryStorageOptions storageOptions) { |
43 | 55 | DurableTaskGrpcWorkerBuilder workerBuilder = SampleUtils.newWorkerBuilder(); |
44 | 56 | ExportHistoryWorkers.register(workerBuilder, client, storageOptions); |
45 | 57 | DurableTaskGrpcWorker worker = workerBuilder.build(); |
46 | 58 | worker.start(); |
| 59 | + return worker; |
| 60 | + } |
47 | 61 |
|
48 | | - System.out.println("Export History Web App started."); |
49 | | - System.out.println("REST API: http://localhost:5009/export-jobs"); |
50 | | - |
51 | | - // Use port 5009 to avoid conflict with DTS emulator on 8080 |
52 | | - System.setProperty("server.port", "5009"); |
53 | | - SpringApplication.run(ExportHistorySample.class, args); |
| 62 | + @Bean |
| 63 | + public ExportHistoryClient exportHistoryClient( |
| 64 | + DurableTaskClient client, ExportHistoryStorageOptions storageOptions) { |
| 65 | + return ExportHistoryClients.create(client, storageOptions); |
54 | 66 | } |
55 | 67 |
|
56 | 68 | private static String env(String name, String defaultValue) { |
|
0 commit comments