@@ -48,6 +48,7 @@ public static async Task Start(Config config)
4848 var loggerFactory = serviceCollection . BuildServiceProvider ( )
4949 . GetService < ILoggerFactory > ( ) ;
5050
51+
5152 if ( loggerFactory != null )
5253 {
5354 var lp = loggerFactory . CreateLogger < Producer > ( ) ;
@@ -84,7 +85,7 @@ public static async Task Start(Config config)
8485
8586 if ( config . LoadBalancer )
8687 {
87- var resolver = new AddressResolver ( new IPEndPoint ( IPAddress . Parse ( config . Host ) , config . Port ) ) ;
88+ var resolver = new AddressResolver ( ep ) ;
8889 streamConf = new StreamSystemConfig ( )
8990 {
9091 AddressResolver = resolver ,
@@ -114,7 +115,6 @@ public static async Task Start(Config config)
114115 var totalError = 0 ;
115116 var totalConsumed = 0 ;
116117 var totalSent = 0 ;
117- var totalSentToSuperStream = 0 ;
118118 var isRunning = true ;
119119
120120 _ = Task . Run ( ( ) =>
@@ -124,12 +124,11 @@ public static async Task Start(Config config)
124124 Console . WriteLine (
125125 $ "When: { DateTime . Now } , " +
126126 $ "Tr { System . Diagnostics . Process . GetCurrentProcess ( ) . Threads . Count } , " +
127+ $ "Sent: { totalSent : #,##0.00} , " +
127128 $ "Conf: { totalConfirmed : #,##0.00} , " +
128129 $ "Error: { totalError : #,##0.00} , " +
129130 $ "Total: { ( totalConfirmed + totalError ) : #,##0.00} , " +
130131 $ "Consumed: { totalConsumed : #,##0.00} , " +
131- $ "Sent: { totalSent : #,##0.00} , " +
132- $ "Sent To SuperStream: { totalSentToSuperStream : #,##0.00} , " +
133132 $ "Sent per stream: { totalSent / streamsList . Count } ") ;
134133 Thread . Sleep ( 5000 ) ;
135134 }
@@ -180,6 +179,11 @@ await system.CreateStream(new StreamSpec(stream) {MaxLengthBytes = 30_000_000_00
180179 await Consumer . Create ( conf , lc ) . ConfigureAwait ( false ) ) ;
181180 }
182181
182+ async Task MaybeSend ( Producer producer , Message message , ManualResetEvent publishEvent )
183+ {
184+ publishEvent . WaitOne ( ) ;
185+ await producer . Send ( message ) . ConfigureAwait ( false ) ;
186+ }
183187
184188 for ( var z = 0 ; z < config . Producers ; z ++ )
185189 {
@@ -215,12 +219,12 @@ await system.CreateStream(new StreamSpec(stream) {MaxLengthBytes = 30_000_000_00
215219 var streamInfo = status . Partition is not null
216220 ? $ " Partition { status . Partition } of super stream: { status . Stream } "
217221 : $ "Stream: { status . Stream } ";
218-
222+
219223 lp . LogInformation ( "Producer: {Id} - status changed from {From} to {To}. {Info}" ,
220- status . Identifier ,
224+ status . Identifier ,
221225 status . From ,
222226 status . To , streamInfo ) ;
223-
227+
224228 if ( status . To == ReliableEntityStatus . Open )
225229 {
226230 publishEvent . Set ( ) ;
@@ -238,14 +242,13 @@ await system.CreateStream(new StreamSpec(stream) {MaxLengthBytes = 30_000_000_00
238242
239243 for ( var i = 0 ; i < config . MessagesPerProducer ; i ++ )
240244 {
241- publishEvent . WaitOne ( ) ;
242245 if ( ! unconfirmedMessages . IsEmpty )
243246 {
244247 var msgs = unconfirmedMessages . ToArray ( ) ;
245248 unconfirmedMessages . Clear ( ) ;
246249 foreach ( var msg in msgs )
247250 {
248- await producer . Send ( msg ) . ConfigureAwait ( false ) ;
251+ await MaybeSend ( producer , msg , publishEvent ) . ConfigureAwait ( false ) ;
249252 Interlocked . Increment ( ref totalSent ) ;
250253 }
251254 }
@@ -254,8 +257,7 @@ await system.CreateStream(new StreamSpec(stream) {MaxLengthBytes = 30_000_000_00
254257 {
255258 Properties = new Properties ( ) { MessageId = $ "hello{ i } "}
256259 } ;
257- await producer . Send ( message ) . ConfigureAwait ( false ) ;
258- await Task . Delay ( 10 ) . ConfigureAwait ( false ) ;
260+ await MaybeSend ( producer , message , publishEvent ) . ConfigureAwait ( false ) ;
259261 Interlocked . Increment ( ref totalSent ) ;
260262 }
261263 } ) ;
@@ -270,6 +272,9 @@ await system.CreateStream(new StreamSpec(stream) {MaxLengthBytes = 30_000_000_00
270272 producersList . ForEach ( async p => await p . Close ( ) . ConfigureAwait ( false ) ) ;
271273 Console . WriteLine ( "closing the consumers ..... " ) ;
272274 consumersList . ForEach ( async c => await c . Close ( ) . ConfigureAwait ( false ) ) ;
275+
276+ Console . WriteLine ( "Press any key to close all" ) ;
277+ Console . ReadKey ( ) ;
273278 }
274279
275280 Console . WriteLine ( "Closed all the consumers and producers" ) ;
0 commit comments