You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently NATS clients will create any missing topics of they are not configured on a stream through NATSConsumerClient.FetchTopics. This requires extra permissions for the client to be configured in the NATS server configuration. e.g:
For use cases when you want to limit the permissions required for a nats client, by having a centralized solution for creating streams & topics, then allowing dynamic creation by clients is not feasible as it currently enforces a client to have the publish permissions specified above.
Therefore I propose to extended the NATSOptions with a new property EnableSubscriberClientStreamAndTopicCreation with default value true in order for the change to be backwards compatible.
Pseudo code:
publicclassNATSOptions{
.../// <summary>/// Allows a nats client to dynamically create a stream and configure its expected topics./// </summary>publicboolEnableSubscriberClientStreamAndTopicCreation{get;set;}=true;
...}
This option would then be used in the NATSConsumerClient.FetchTopics method like the following in order to avoid doing calls requiring described client publish permissions via the the JetsManagementContext class.
publicICollection<string>FetchTopics(IEnumerable<string>topicNames){if(_natsOptions.EnableSubscriberClientStreamAndTopicCreation){
Connect();varjsm=_consumerClient!.CreateJetStreamManagementContext();varstreamGroup= topicNames.GroupBy(x => _natsOptions.NormalizeStreamName(x));foreach(var subjectStream in streamGroup){varbuilder= StreamConfiguration.Builder().WithName(subjectStream.Key).WithNoAck(false).WithStorageType(StorageType.Memory).WithSubjects(subjectStream.ToList());
_natsOptions.StreamOptions?.Invoke(builder);try{
jsm.GetStreamInfo(subjectStream.Key);// this throws if the stream does not exist
jsm.UpdateStream(builder.Build());}catch(NATSJetStreamException){try{
jsm.AddStream(builder.Build());}catch{// ignored}}}}return topicNames.ToList();}
The text was updated successfully, but these errors were encountered:
Currently NATS clients will create any missing topics of they are not configured on a stream through
NATSConsumerClient.FetchTopics
. This requires extra permissions for the client to be configured in the NATS server configuration. e.g:For use cases when you want to limit the permissions required for a nats client, by having a centralized solution for creating streams & topics, then allowing dynamic creation by clients is not feasible as it currently enforces a client to have the publish permissions specified above.
Therefore I propose to extended the
NATSOptions
with a new propertyEnableSubscriberClientStreamAndTopicCreation
with default valuetrue
in order for the change to be backwards compatible.Pseudo code:
This option would then be used in the
NATSConsumerClient.FetchTopics
method like the following in order to avoid doing calls requiring described client publish permissions via the the JetsManagementContext class.The text was updated successfully, but these errors were encountered: