File tree Expand file tree Collapse file tree
ActivityHeartbeatingCancellation
OpenTelemetry/CoreSdkForwarding
UpdateWithStartEarlyReturn Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using Microsoft . Extensions . Logging ;
22using Temporalio . Client ;
3+ using Temporalio . Client . EnvConfig ;
34using Temporalio . Exceptions ;
45using Temporalio . Worker ;
56using TemporalioSamples . ActivityHeartbeatingCancellation ;
67
78// Create a client to localhost on default namespace
8- var client = await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
9+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
10+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
911{
10- LoggerFactory = LoggerFactory . Create ( builder =>
11- builder .
12- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
13- SetMinimumLevel ( LogLevel . Information ) ) ,
14- } ) ;
12+ connectOptions . TargetHost = "localhost:7233" ;
13+ }
14+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
15+ builder .
16+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
17+ SetMinimumLevel ( LogLevel . Information ) ) ;
18+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
1519
1620async Task RunWorkerAsync ( )
1721{
Original file line number Diff line number Diff line change 11using Microsoft . Extensions . Logging ;
22using Temporalio . Client ;
3+ using Temporalio . Client . EnvConfig ;
34using Temporalio . Worker ;
45using TemporalioSamples . ActivitySimple ;
56
67// Create a client to localhost on default namespace
7- var client = await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
8+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
9+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
810{
9- LoggerFactory = LoggerFactory . Create ( builder =>
10- builder .
11- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
12- SetMinimumLevel ( LogLevel . Information ) ) ,
13- } ) ;
11+ connectOptions . TargetHost = "localhost:7233" ;
12+ }
13+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
14+ builder .
15+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
16+ SetMinimumLevel ( LogLevel . Information ) ) ;
17+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
1418
1519async Task RunWorkerAsync ( )
1620{
Original file line number Diff line number Diff line change 11using Temporalio . Activities ;
22using Temporalio . Client ;
3+ using Temporalio . Client . EnvConfig ;
34using Temporalio . Worker ;
45using Temporalio . Workflows ;
56using TemporalioSamples . ActivityWorker ;
67
78// Create a client to localhost on default namespace
8- var client = await TemporalClient . ConnectAsync ( new ( "localhost:7233" ) ) ;
9+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
10+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
11+ {
12+ connectOptions . TargetHost = "localhost:7233" ;
13+ }
14+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
915
1016// Create worker
1117using var worker = new TemporalWorker (
Original file line number Diff line number Diff line change 11using Temporalio . Client ;
2+ using Temporalio . Client . EnvConfig ;
23using TemporalioSamples . AspNet . Worker ;
34
45var builder = WebApplication . CreateBuilder ( args ) ;
910// Set a singleton for the client _task_. Errors will not happen here, only when
1011// the await is performed.
1112builder . Services . AddSingleton ( ctx =>
13+ {
1214 // TODO(cretz): It is not great practice to pass around tasks to be awaited
1315 // on separately (VSTHRD003). We may prefer a direct DI extension, see
1416 // https://github.com/temporalio/sdk-dotnet/issues/46.
15- TemporalClient . ConnectAsync ( new ( )
17+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
18+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
1619 {
17- TargetHost = "localhost:7233" ,
18- LoggerFactory = ctx . GetRequiredService < ILoggerFactory > ( ) ,
19- } ) ) ;
20+ connectOptions . TargetHost = "localhost:7233" ;
21+ }
22+ connectOptions . LoggerFactory = ctx . GetRequiredService < ILoggerFactory > ( ) ;
23+ return TemporalClient . ConnectAsync ( connectOptions ) ;
24+ } ) ;
2025
2126var app = builder . Build ( ) ;
2227
Original file line number Diff line number Diff line change 33using Microsoft . Extensions . Hosting ;
44using Microsoft . Extensions . Logging ;
55using Temporalio . Client ;
6+ using Temporalio . Client . EnvConfig ;
67using Temporalio . Extensions . Hosting ;
78using TemporalioSamples . Bedrock . Basic ;
89
@@ -47,14 +48,19 @@ async Task SendMessageAsync()
4748 Console . WriteLine ( $ "Result: { result . Response } ") ;
4849}
4950
50- async Task < ITemporalClient > CreateClientAsync ( ) =>
51- await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
51+ async Task < ITemporalClient > CreateClientAsync ( )
52+ {
53+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
54+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
5255 {
53- LoggerFactory = LoggerFactory . Create ( builder =>
54- builder .
55- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
56- SetMinimumLevel ( LogLevel . Information ) ) ,
57- } ) ;
56+ connectOptions . TargetHost = "localhost:7233" ;
57+ }
58+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
59+ builder .
60+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
61+ SetMinimumLevel ( LogLevel . Information ) ) ;
62+ return await TemporalClient . ConnectAsync ( connectOptions ) ;
63+ }
5864
5965switch ( args . ElementAtOrDefault ( 0 ) )
6066{
Original file line number Diff line number Diff line change 33using Microsoft . Extensions . Hosting ;
44using Microsoft . Extensions . Logging ;
55using Temporalio . Client ;
6+ using Temporalio . Client . EnvConfig ;
67using Temporalio . Extensions . Hosting ;
78using TemporalioSamples . Bedrock . Entity ;
89
@@ -78,14 +79,19 @@ async Task EndChatAsync()
7879 await handle . SignalAsync ( ( workflow ) => workflow . EndChatAsync ( ) ) ;
7980}
8081
81- async Task < ITemporalClient > CreateClientAsync ( ) =>
82- await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
82+ async Task < ITemporalClient > CreateClientAsync ( )
83+ {
84+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
85+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
8386 {
84- LoggerFactory = LoggerFactory . Create ( builder =>
85- builder .
86- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
87- SetMinimumLevel ( LogLevel . Information ) ) ,
88- } ) ;
87+ connectOptions . TargetHost = "localhost:7233" ;
88+ }
89+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
90+ builder .
91+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
92+ SetMinimumLevel ( LogLevel . Information ) ) ;
93+ return await TemporalClient . ConnectAsync ( connectOptions ) ;
94+ }
8995
9096switch ( args . ElementAtOrDefault ( 0 ) )
9197{
Original file line number Diff line number Diff line change 33using Microsoft . Extensions . Hosting ;
44using Microsoft . Extensions . Logging ;
55using Temporalio . Client ;
6+ using Temporalio . Client . EnvConfig ;
67using Temporalio . Extensions . Hosting ;
78using TemporalioSamples . Bedrock . SignalsAndQueries ;
89
@@ -69,14 +70,19 @@ async Task GetHistoryAsync()
6970 }
7071}
7172
72- async Task < ITemporalClient > CreateClientAsync ( ) =>
73- await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
73+ async Task < ITemporalClient > CreateClientAsync ( )
74+ {
75+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
76+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
7477 {
75- LoggerFactory = LoggerFactory . Create ( builder =>
76- builder .
77- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
78- SetMinimumLevel ( LogLevel . Information ) ) ,
79- } ) ;
78+ connectOptions . TargetHost = "localhost:7233" ;
79+ }
80+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
81+ builder .
82+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
83+ SetMinimumLevel ( LogLevel . Information ) ) ;
84+ return await TemporalClient . ConnectAsync ( connectOptions ) ;
85+ }
8086
8187switch ( args . ElementAtOrDefault ( 0 ) )
8288{
Original file line number Diff line number Diff line change 11using Microsoft . Extensions . Logging ;
22using Temporalio . Client ;
3+ using Temporalio . Client . EnvConfig ;
34using Temporalio . Converters ;
45using Temporalio . Worker ;
56using TemporalioSamples . ContextPropagation ;
1112var logger = loggerFactory . CreateLogger < Program > ( ) ;
1213
1314// Create a client to localhost on default namespace
14- var client = await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
15+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
16+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
1517{
16- LoggerFactory = loggerFactory ,
17- // This is where we set the interceptor to propagate context
18- Interceptors = new [ ]
19- {
20- new ContextPropagationInterceptor < string > (
21- MyContext . UserId ,
22- DataConverter . Default . PayloadConverter ) ,
23- } ,
24- } ) ;
18+ connectOptions . TargetHost = "localhost:7233" ;
19+ }
20+ connectOptions . LoggerFactory = loggerFactory ;
21+ // This is where we set the interceptor to propagate context
22+ connectOptions . Interceptors = new [ ]
23+ {
24+ new ContextPropagationInterceptor < string > (
25+ MyContext . UserId ,
26+ DataConverter . Default . PayloadConverter ) ,
27+ } ;
28+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
2529
2630async Task RunWorkerAsync ( )
2731{
Original file line number Diff line number Diff line change 11namespace TemporalioSamples . CounterInterceptor ;
22
33using Temporalio . Client ;
4+ using Temporalio . Client . EnvConfig ;
45using Temporalio . Worker ;
56
67internal class Program
78{
89 private static async Task Main ( string [ ] args )
910 {
1011 var counterInterceptor = new MyCounterInterceptor ( ) ;
11- var client = await TemporalClient . ConnectAsync (
12- options : new ( "localhost:7233" )
13- {
14- Interceptors = new [ ]
15- {
16- counterInterceptor ,
17- } ,
18- } ) ;
12+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
13+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
14+ {
15+ connectOptions . TargetHost = "localhost:7233" ;
16+ }
17+ connectOptions . Interceptors = new [ ]
18+ {
19+ counterInterceptor ,
20+ } ;
21+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
1922
2023 var activities = new MyActivities ( ) ;
2124
Original file line number Diff line number Diff line change 11using Temporalio . Client ;
2+ using Temporalio . Client . EnvConfig ;
23using Temporalio . Extensions . Hosting ;
34using TemporalioSamples . DependencyInjection ;
45
@@ -25,13 +26,16 @@ async Task RunWorkerAsync()
2526
2627async Task ExecuteWorkflowAsync ( )
2728{
28- var client = await TemporalClient . ConnectAsync ( new ( "localhost:7233" )
29+ var connectOptions = ClientEnvConfig . LoadClientConnectOptions ( ) ;
30+ if ( string . IsNullOrEmpty ( connectOptions . TargetHost ) )
2931 {
30- LoggerFactory = LoggerFactory . Create ( builder =>
31- builder .
32- AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
33- SetMinimumLevel ( LogLevel . Information ) ) ,
34- } ) ;
32+ connectOptions . TargetHost = "localhost:7233" ;
33+ }
34+ connectOptions . LoggerFactory = LoggerFactory . Create ( builder =>
35+ builder .
36+ AddSimpleConsole ( options => options . TimestampFormat = "[HH:mm:ss] " ) .
37+ SetMinimumLevel ( LogLevel . Information ) ) ;
38+ var client = await TemporalClient . ConnectAsync ( connectOptions ) ;
3539
3640 Console . WriteLine ( "Executing workflow" ) ;
3741 var result = await client . ExecuteWorkflowAsync (
You can’t perform that action at this time.
0 commit comments