...

Source file src/solace.dev/go/messaging/pkg/solace/config/message_publisher_properties.go

Documentation: solace.dev/go/messaging/pkg/solace/config

     1  // pubsubplus-go-client
     2  //
     3  // Copyright 2021-2024 Solace Corporation. All rights reserved.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  // http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package config
    18  
    19  // PublisherPropertiesConfigurationProvider describes the behavior of a configuration provider
    20  // that provides properties for publishers.
    21  type PublisherPropertiesConfigurationProvider interface {
    22  	GetConfiguration() PublisherPropertyMap
    23  }
    24  
    25  // PublisherProperty is a property that can be set on a publisher.
    26  type PublisherProperty string
    27  
    28  // PublisherPropertyMap is a map of PublisherProperty keys to values.
    29  type PublisherPropertyMap map[PublisherProperty]interface{}
    30  
    31  // GetConfiguration returns a copy of the PublisherPropertyMap.
    32  func (publisherPropertyMap PublisherPropertyMap) GetConfiguration() PublisherPropertyMap {
    33  	ret := make(PublisherPropertyMap)
    34  	for key, value := range publisherPropertyMap {
    35  		ret[key] = value
    36  	}
    37  	return ret
    38  }
    39  
    40  // MarshalJSON implements the json.Marshaler interface.
    41  func (publisherPropertyMap PublisherPropertyMap) MarshalJSON() ([]byte, error) {
    42  	m := make(map[string]interface{})
    43  	for k, v := range publisherPropertyMap {
    44  		m[string(k)] = v
    45  	}
    46  	return nestJSON(m)
    47  }
    48  
    49  // UnmarshalJSON implements the json.Unmarshaler interface.
    50  func (publisherPropertyMap PublisherPropertyMap) UnmarshalJSON(b []byte) error {
    51  	m, err := flattenJSON(b)
    52  	if err != nil {
    53  		return err
    54  	}
    55  	for key, val := range m {
    56  		publisherPropertyMap[PublisherProperty(key)] = val
    57  	}
    58  	return nil
    59  }
    60  
    61  const (
    62  	// PublisherPropertyBackPressureStrategy sets the back pressure strategy on a publisher.
    63  	// Valid values are BUFFER_WAIT_WHEN_FULL or BUFFER_REJECT_WHEN_FULL where BUFFER_WAIT_WHEN_FULL
    64  	// will block until space is available and BUFFER_REJECT_WHEN_FULL will return an error if the buffer
    65  	// is full.
    66  	PublisherPropertyBackPressureStrategy PublisherProperty = "solace.messaging.publisher.back-pressure.strategy"
    67  	// PublisherPropertyBackPressureBufferCapacity sets the buffer size of the publisher.
    68  	// Valid values are greater than or equal to 1 for back pressure strategy Wait and greater than or
    69  	// equal to 0 for back pressure strategy Reject.
    70  	PublisherPropertyBackPressureBufferCapacity PublisherProperty = "solace.messaging.publisher.back-pressure.buffer-capacity"
    71  )
    72