99
1010var title = string . IsNullOrEmpty ( instancePostfix ) ? "Failure rate (Billing)" : $ "Billing - { instancePostfix } ";
1111var instanceName = string . IsNullOrEmpty ( instancePostfix ) ? "billing" : $ "billing-{ instancePostfix } ";
12-
1312var instanceId = DeterministicGuid . Create ( "Billing" , instanceName ) ;
13+ var prometheusPortString = args . Skip ( 1 ) . FirstOrDefault ( ) ;
1414
15- var endpointConfiguration = new EndpointConfiguration ( "Billing" ) ;
16- endpointConfiguration . LimitMessageProcessingConcurrencyTo ( 4 ) ;
15+ var endpointControls = new ProcessingEndpointControls ( ( ) => PrepareEndpointConfiguration ( instanceId , instanceName , prometheusPortString ) ) ;
1716
18- var serializer = endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
19- serializer . Options ( new JsonSerializerOptions
20- {
21- TypeInfoResolverChain =
22- {
23- MessagesSerializationContext . Default
24- }
25- } ) ;
17+ var ui = new UserInterface ( ) ;
18+ endpointControls . BindSlowProcessingDial ( ui , '5' , 't' ) ;
19+ endpointControls . BindDatabaseFailuresDial ( ui , '6' , 'y' ) ;
20+
21+ endpointControls . BindDatabaseDownToggle ( ui , 'f' ) ;
22+ endpointControls . BindDelayedRetriesToggle ( ui , 'g' ) ;
23+ endpointControls . BindAutoThrottleToggle ( ui , 'h' ) ;
2624
27- var transport = new LearningTransport
25+ endpointControls . BindFailureReceivingButton ( ui , 'v' ) ;
26+ endpointControls . BindFailureProcessingButton ( ui , 'b' ) ;
27+ endpointControls . BindFailureDispatchingButton ( ui , 'n' ) ;
28+
29+ if ( prometheusPortString != null )
2830{
29- StorageDirectory = Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) ! . Parent ! . FullName , ".learningtransport" ) ,
30- TransportTransactionMode = TransportTransactionMode . ReceiveOnly
31- } ;
32- endpointConfiguration . UseTransport ( transport ) ;
31+ OpenTelemetryUtils . ConfigureOpenTelemetry ( "Billing" , instanceId . ToString ( ) , int . Parse ( prometheusPortString ) ) ;
32+ }
3333
34- endpointConfiguration . Recoverability ( )
35- . Delayed ( delayed => delayed . NumberOfRetries ( 0 ) ) ;
34+ endpointControls . Start ( ) ;
3635
37- endpointConfiguration . AuditProcessedMessagesTo ( "audit" ) ;
38- endpointConfiguration . SendHeartbeatTo ( "Particular.ServiceControl" ) ;
36+ ui . RunLoop ( title ) ;
3937
40- endpointConfiguration . UniquelyIdentifyRunningInstance ( )
41- . UsingCustomIdentifier ( instanceId )
42- . UsingCustomDisplayName ( instanceName ) ;
38+ await endpointControls . StopEndpoint ( ) ;
4339
44- var metrics = endpointConfiguration . EnableMetrics ( ) ;
45- metrics . SendMetricDataToServiceControl (
46- "Particular.Monitoring" ,
47- TimeSpan . FromMilliseconds ( 500 )
48- ) ;
40+ EndpointConfiguration PrepareEndpointConfiguration ( Guid guid , string s , string ? prometheusPortString1 )
41+ {
42+ var endpointConfiguration1 = new EndpointConfiguration ( "Billing" ) ;
43+ endpointConfiguration1 . LimitMessageProcessingConcurrencyTo ( 4 ) ;
4944
50- endpointConfiguration . UsePersistence < NonDurablePersistence > ( ) ;
51- endpointConfiguration . EnableOutbox ( ) ;
45+ var serializer = endpointConfiguration1 . UseSerialization < SystemJsonSerializer > ( ) ;
46+ serializer . Options ( new JsonSerializerOptions
47+ {
48+ TypeInfoResolverChain =
49+ {
50+ MessagesSerializationContext . Default
51+ }
52+ } ) ;
5253
53- var failureSimulation = new FailureSimulation ( ) ;
54- failureSimulation . Register ( endpointConfiguration ) ;
54+ var transport = new LearningTransport
55+ {
56+ StorageDirectory = Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) ! . Parent ! . FullName , ".learningtransport" ) ,
57+ TransportTransactionMode = TransportTransactionMode . ReceiveOnly
58+ } ;
59+ endpointConfiguration1 . UseTransport ( transport ) ;
5560
56- var simulationEffects = new SimulationEffects ( ) ;
57- endpointConfiguration . RegisterComponents ( cc => cc . AddSingleton ( simulationEffects ) ) ;
61+ endpointConfiguration1 . Recoverability ( )
62+ . Delayed ( delayed => delayed . NumberOfRetries ( 0 ) ) ;
5863
59- var endpointInstance = await Endpoint . Start ( endpointConfiguration ) ;
64+ endpointConfiguration1 . AuditProcessedMessagesTo ( "audit" ) ;
65+ endpointConfiguration1 . SendHeartbeatTo ( "Particular.ServiceControl" ) ;
6066
61- UserInterface . RunLoop ( title , new Dictionary < char , ( string , Action ) >
62- {
63- [ 'w' ] = ( "increase the simulated failure rate" , ( ) => simulationEffects . IncreaseFailureRate ( ) ) ,
64- [ 's' ] = ( "decrease the simulated failure rate" , ( ) => simulationEffects . DecreaseFailureRate ( ) )
65- } , writer => simulationEffects . WriteState ( writer ) ) ;
67+ endpointConfiguration1 . UniquelyIdentifyRunningInstance ( )
68+ . UsingCustomIdentifier ( guid )
69+ . UsingCustomDisplayName ( s ) ;
70+
71+ var metrics = endpointConfiguration1 . EnableMetrics ( ) ;
72+ metrics . SendMetricDataToServiceControl (
73+ "Particular.Monitoring" ,
74+ TimeSpan . FromMilliseconds ( 500 )
75+ ) ;
76+
77+ endpointConfiguration1 . UsePersistence < NonDurablePersistence > ( ) ;
78+ endpointConfiguration1 . EnableOutbox ( ) ;
79+
80+ endpointConfiguration1 . EnableOpenTelemetry ( ) ;
6681
67- await endpointInstance . Stop ( ) ;
82+ return endpointConfiguration1 ;
83+ }
0 commit comments