@@ -299,6 +299,77 @@ type JSApiStreamLeaderStepDownResponse struct {
299299 Success bool `json:"success,omitempty"`
300300}
301301
302+ type PersistModeType int
303+
304+ const (
305+ // DefaultPersistMode specifies the default persist mode. Writes to the stream will immediately be flushed.
306+ // The publish acknowledgement will be sent after the persisting completes.
307+ DefaultPersistMode = PersistModeType (iota )
308+ // AsyncPersistMode specifies writes to the stream will be flushed asynchronously.
309+ // The publish acknowledgement may be sent before the persisting completes.
310+ // This means writes could be lost if they weren't flushed prior to a hard kill of the server.
311+ AsyncPersistMode
312+ )
313+
314+ func (wc PersistModeType ) String () string {
315+ switch wc {
316+ case DefaultPersistMode :
317+ return "Default"
318+ case AsyncPersistMode :
319+ return "Async"
320+ default :
321+ return "Unknown Persist Mode Type"
322+ }
323+ }
324+
325+ func (wc PersistModeType ) MarshalJSON () ([]byte , error ) {
326+ switch wc {
327+ case DefaultPersistMode :
328+ return json .Marshal ("default" )
329+ case AsyncPersistMode :
330+ return json .Marshal ("async" )
331+ default :
332+ return nil , fmt .Errorf ("can not marshal %v" , wc )
333+ }
334+ }
335+
336+ func (wc PersistModeType ) MarshalYAML () (any , error ) {
337+ switch wc {
338+ case DefaultPersistMode :
339+ return "default" , nil
340+ case AsyncPersistMode :
341+ return "async" , nil
342+ default :
343+ return nil , fmt .Errorf ("can not marshal %v" , wc )
344+ }
345+ }
346+
347+ func (wc * PersistModeType ) UnmarshalJSON (data []byte ) error {
348+ switch string (data ) {
349+ case jsonString ("default" ), jsonString ("" ):
350+ * wc = DefaultPersistMode
351+ case jsonString ("async" ):
352+ * wc = AsyncPersistMode
353+ default :
354+ return fmt .Errorf ("can not unmarshal %q" , data )
355+ }
356+
357+ return nil
358+ }
359+
360+ func (wc * PersistModeType ) UnmarshalYAML (data * yaml.Node ) error {
361+ switch data .Value {
362+ case "" , "default" :
363+ * wc = DefaultPersistMode
364+ case "async" :
365+ * wc = AsyncPersistMode
366+ default :
367+ return fmt .Errorf ("can not unmarshal %q" , data .Value )
368+ }
369+
370+ return nil
371+ }
372+
302373type DiscardPolicy int
303374
304375const (
@@ -637,6 +708,8 @@ type StreamConfig struct {
637708 AllowMsgCounter bool `json:"allow_msg_counter,omitempty" yaml:"allow_msg_counter" api_level:"2"`
638709 // AllowMsgSchedules allows the scheduling of messages.
639710 AllowMsgSchedules bool `json:"allow_msg_schedules,omitempty" yaml:"allow_msg_schedules" api_level:"2"`
711+ // PersistMode allows to opt-in to different persistence mode settings.
712+ PersistMode PersistModeType `json:"persist_mode,omitempty" yaml:"persist_mode" api_level:"2"`
640713}
641714
642715// StreamConsumerLimits describes limits and defaults for consumers created on a stream
0 commit comments