@@ -67,8 +67,10 @@ public async ValueTask<INatsJSConsumer> UpdateConsumerAsync(
6767 public async ValueTask < INatsJSConsumer > GetConsumerAsync ( string stream , string consumer , CancellationToken cancellationToken = default )
6868 {
6969 ThrowIfInvalidStreamName ( stream ) ;
70- var props = GetConsumerProps ( "INFO" , stream , consumer ) ;
71- var response = await JSRequestResponseAsync < object , ConsumerInfo > ( props , null , cancellationToken ) ;
70+ var response = await JSRequestResponseAsync < object , ConsumerInfo > (
71+ subject : $ "{ Opts . Prefix } .CONSUMER.INFO.{ stream } .{ consumer } ",
72+ request : null ,
73+ cancellationToken ) ;
7274 return new NatsJSConsumer ( this , response ) ;
7375 }
7476
@@ -79,11 +81,10 @@ public async IAsyncEnumerable<INatsJSConsumer> ListConsumersAsync(
7981 {
8082 ThrowIfInvalidStreamName ( stream ) ;
8183 var offset = 0 ;
82- var props = GetConsumerProps ( "LIST" , stream ) ;
8384 while ( ! cancellationToken . IsCancellationRequested )
8485 {
8586 var response = await JSRequestResponseAsync < ConsumerListRequest , ConsumerListResponse > (
86- props : props ,
87+ subject : $ " { Opts . Prefix } .CONSUMER.LIST. { stream } " ,
8788 new ConsumerListRequest { Offset = offset } ,
8889 cancellationToken ) ;
8990
@@ -106,11 +107,10 @@ public async IAsyncEnumerable<string> ListConsumerNamesAsync(
106107 {
107108 ThrowIfInvalidStreamName ( stream ) ;
108109 var offset = 0 ;
109- var props = GetConsumerProps ( "NAMES" , stream ) ;
110110 while ( ! cancellationToken . IsCancellationRequested )
111111 {
112112 var response = await JSRequestResponseAsync < ConsumerNamesRequest , ConsumerNamesResponse > (
113- props : props ,
113+ subject : $ " { Opts . Prefix } .CONSUMER.NAMES. { stream } " ,
114114 new ConsumerNamesRequest { Offset = offset } ,
115115 cancellationToken ) ;
116116
@@ -138,8 +138,10 @@ public async IAsyncEnumerable<string> ListConsumerNamesAsync(
138138 public async ValueTask < bool > DeleteConsumerAsync ( string stream , string consumer , CancellationToken cancellationToken = default )
139139 {
140140 ThrowIfInvalidStreamName ( stream ) ;
141- var props = GetConsumerProps ( "DELETE" , stream , consumer ) ;
142- var response = await JSRequestResponseAsync < object , ConsumerDeleteResponse > ( props , null , cancellationToken ) ;
141+ var response = await JSRequestResponseAsync < object , ConsumerDeleteResponse > (
142+ subject : $ "{ Opts . Prefix } .CONSUMER.DELETE.{ stream } .{ consumer } ",
143+ request : null ,
144+ cancellationToken ) ;
143145 return response . Success ;
144146 }
145147
@@ -159,7 +161,7 @@ public async ValueTask<ConsumerPauseResponse> PauseConsumerAsync(string stream,
159161 {
160162 ThrowIfInvalidStreamName ( stream ) ;
161163 var response = await JSRequestResponseAsync < ConsumerPauseRequest , ConsumerPauseResponse > (
162- props : GetConsumerProps ( " PAUSE" , stream , consumer ) ,
164+ subject : $ " { Opts . Prefix } .CONSUMER. PAUSE. { stream } . { consumer } " ,
163165 request : new ConsumerPauseRequest { PauseUntil = pauseUntil } ,
164166 cancellationToken ) ;
165167 return response ;
@@ -179,8 +181,10 @@ public async ValueTask<ConsumerPauseResponse> PauseConsumerAsync(string stream,
179181 public async ValueTask < bool > ResumeConsumerAsync ( string stream , string consumer , CancellationToken cancellationToken = default )
180182 {
181183 ThrowIfInvalidStreamName ( stream ) ;
182- var props = GetConsumerProps ( "PAUSE" , stream , consumer ) ;
183- var response = await JSRequestResponseAsync < object , ConsumerPauseResponse > ( props , null , cancellationToken ) ;
184+ var response = await JSRequestResponseAsync < object , ConsumerPauseResponse > (
185+ subject : $ "{ Opts . Prefix } .CONSUMER.PAUSE.{ stream } .{ consumer } ",
186+ request : null ,
187+ cancellationToken ) ;
184188 return ! response . IsPaused ;
185189 }
186190
@@ -225,9 +229,12 @@ internal ValueTask<ConsumerInfo> CreateOrderedConsumerInternalAsync(
225229 }
226230
227231 var name = Nuid . NewNuid ( ) ;
228- var props = GetConsumerProps ( " CREATE" , stream , name ) ;
232+ var subject = $ " { Opts . Prefix } .CONSUMER. CREATE. { stream } . { name } " ;
229233
230- return JSRequestResponseAsync < ConsumerCreateRequest , ConsumerInfo > ( props , request , cancellationToken ) ;
234+ return JSRequestResponseAsync < ConsumerCreateRequest , ConsumerInfo > (
235+ subject : subject ,
236+ request ,
237+ cancellationToken ) ;
231238 }
232239
233240 private async ValueTask < NatsJSConsumer > CreateOrUpdateConsumerInternalAsync (
@@ -236,12 +243,16 @@ private async ValueTask<NatsJSConsumer> CreateOrUpdateConsumerInternalAsync(
236243 ConsumerCreateAction action ,
237244 CancellationToken cancellationToken )
238245 {
239- var props = GetConsumerProps ( "CREATE" , stream , config . Name ) ;
246+ var subject = $ "{ Opts . Prefix } .CONSUMER.CREATE.{ stream } ";
247+
248+ if ( ! string . IsNullOrWhiteSpace ( config . Name ) )
249+ {
250+ subject += $ ".{ config . Name } ";
251+ }
240252
241- if ( ! string . IsNullOrWhiteSpace ( config . FilterSubject ) && config . FilterSubject != null )
253+ if ( ! string . IsNullOrWhiteSpace ( config . FilterSubject ) )
242254 {
243- props . Subject . Values . Add ( "filterSubject" , config . FilterSubject ) ;
244- props . Subject . Template += ".filterSubject" ;
255+ subject += $ ".{ config . FilterSubject } ";
245256 }
246257
247258 // ADR-42: In the initial implementation we should limit PriorityGroups to one per consumer only
@@ -264,7 +275,7 @@ private async ValueTask<NatsJSConsumer> CreateOrUpdateConsumerInternalAsync(
264275 }
265276
266277 var response = await JSRequestResponseAsync < ConsumerCreateRequest , ConsumerInfo > (
267- props : props ,
278+ subject : subject ,
268279 new ConsumerCreateRequest
269280 {
270281 StreamName = stream ,
@@ -275,23 +286,4 @@ private async ValueTask<NatsJSConsumer> CreateOrUpdateConsumerInternalAsync(
275286
276287 return new NatsJSConsumer ( this , response ) ;
277288 }
278-
279- private NatsPublishProps GetConsumerProps ( string action , string stream , string ? consumer = default )
280- {
281- var template = "{prefix}.{entity}.{action}.{stream}" ;
282- var values = new Dictionary < string , object > ( )
283- {
284- { "prefix" , Opts . Prefix } ,
285- { "entity" , "CONSUMER" } ,
286- { "action" , action } ,
287- { "stream" , stream } ,
288- } ;
289- if ( consumer != null )
290- {
291- template += ".{id}" ;
292- values . Add ( "id" , consumer ) ;
293- }
294-
295- return new NatsPublishProps ( template , values ) ;
296- }
297289}
0 commit comments