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 // MessagePropertiesConfigurationProvider describes the behavior of a configuration provider 20 // that provides properties for messages. 21 type MessagePropertiesConfigurationProvider interface { 22 // GetConfiguration returns a copy of the configuration of the MessagePropertiesConfigurationProvider 23 // as a MessagePropertyMap. 24 GetConfiguration() MessagePropertyMap 25 } 26 27 // MessageProperty is a property that can be set on a messages. 28 type MessageProperty string 29 30 // MessagePropertyMap is a map of MessageProperty keys to values. 31 type MessagePropertyMap map[MessageProperty]interface{} 32 33 // GetConfiguration returns a copy of the MessagePropertyMap 34 func (messagePropertyMap MessagePropertyMap) GetConfiguration() MessagePropertyMap { 35 ret := make(MessagePropertyMap) 36 for key, value := range messagePropertyMap { 37 ret[key] = value 38 } 39 return ret 40 } 41 42 // MarshalJSON implements the json.Marshaler interface. 43 func (messagePropertyMap MessagePropertyMap) MarshalJSON() ([]byte, error) { 44 m := make(map[string]interface{}) 45 for k, v := range messagePropertyMap { 46 m[string(k)] = v 47 } 48 return nestJSON(m) 49 } 50 51 // UnmarshalJSON implements the json.Unmarshaler interface. 52 func (messagePropertyMap MessagePropertyMap) UnmarshalJSON(b []byte) error { 53 m, err := flattenJSON(b) 54 if err != nil { 55 return err 56 } 57 for key, val := range m { 58 messagePropertyMap[MessageProperty(key)] = val 59 } 60 return nil 61 } 62 63 // These constants are used as keys in a MessagePropertyMap to configure the message. 64 const ( 65 // MessagePropertyApplicationMessageType specifies an application message type. This value is only used by applications, 66 // and is passed through this API unmodified. 67 MessagePropertyApplicationMessageType MessageProperty = "solace.messaging.message.application-message-type" 68 69 // MessagePropertyApplicationMessageID specifies an application-specific message identifier. This value is used by 70 // applications only, and is passed through the API unmodified. 71 MessagePropertyApplicationMessageID MessageProperty = "solace.messaging.message.application-message-id" 72 73 // MessagePropertyElidingEligible specifies whether the message is eligible for eliding. 74 MessagePropertyElidingEligible MessageProperty = "solace.messaging.message.eliding-eligible" 75 76 // MessagePropertyPriority specifies an optional message priority. 77 // The valid priority value range is 0-255 with 0 as the lowest priority and 255 as the 78 // highest. A value of -1 indicates the priority is not set and that a default priority value is used 79 // instead. 80 MessagePropertyPriority MessageProperty = "solace.messaging.message.priority" 81 82 // MessagePropertyHTTPContentType specifies the HTTP content-type header value for interaction with an HTTP client. 83 // Accepted values Defined in RFC7231, Section-3.1.2.2. 84 MessagePropertyHTTPContentType MessageProperty = "solace.messaging.message.http-content" 85 86 // MessagePropertyHTTPContentEncoding specifies the HTTP content-type encoding value for interaction with an HTTP client. 87 // Accepted values Defined in rfc2616 section-14.11 88 MessagePropertyHTTPContentEncoding MessageProperty = "solace.messaging.message.http-encoding" 89 90 // MessagePropertyCorrelationID key specifies a correlation ID. The correlation ID is used for correlating a request 91 // to a reply and should be as random as possible. 92 // This variable is being also used for the Request-Reply API. For this reason, it is not recommended 93 // to use this property on a message builder instance but only on a publisher interface 94 // where it's available. 95 MessagePropertyCorrelationID MessageProperty = "solace.messaging.message.correlation-id" 96 97 // MessagePropertyPersistentTimeToLive specifies the number of milliseconds before the message is discarded or moved to a 98 // Dead Message Queue. The default value is 0, which means the message never expires. 99 // This key is valid only for persistent messages 100 MessagePropertyPersistentTimeToLive MessageProperty = "solace.messaging.message.persistent.time-to-live" 101 102 // MessagePropertyPersistentExpiration specifies the UTC time (in milliseconds, from midnight, January 1, 1970 UTC) 103 // and indicates when the message is supposed to expire. Setting this property has no effect if the TimeToLive 104 // is set in the same message. It is carried to clients that receive the message, unmodified, and 105 // does not effect the life cycle of the message. This property is only valid for persistent messages. 106 MessagePropertyPersistentExpiration MessageProperty = "solace.messaging.message.persistent.expiration" 107 108 // MessagePropertyPersistentDMQEligible specifies if a message is eligible to be moved to a Dead Message Queue. 109 // The default value is true. This property is valid only for persistent messages. 110 MessagePropertyPersistentDMQEligible MessageProperty = "solace.messaging.message.persistent.dmq-eligible" 111 112 // MessagePropertyPersistentAckImmediately specifies if an appliance should ACK this message immediately upon message receipt. 113 // The default value is false. This property is valid only for persistent messages 114 MessagePropertyPersistentAckImmediately MessageProperty = "solace.messaging.message.persistent.ack-immediately" 115 116 // MessagePropertySequenceNumber specifies the sequence number of the message. If sequence number generation is 117 // enabled, this key overrides the generated value. This field can be set 118 // automatically during message publishing, but existing values are not overwritten when set, as 119 // when a message is sent multiple times. 120 MessagePropertySequenceNumber MessageProperty = "solace.messaging.message.persistent.sequence-number" 121 122 // MessagePropertyClassOfService specifies the class of service to set on the message. 123 // Valid class of service values are 124 // 0 | COS_1 125 // 1 | COS_2 126 // 2 | COS_3 127 MessagePropertyClassOfService MessageProperty = "solace.messaging.message.class-of-service" 128 129 // MessagePropertySenderID specifies a custom sender ID in the message header. 130 // The given value is converted to a string. If set to nil, the sender ID is not set, 131 // however a sender ID is still generated if ServicePropertyGenerateSenderID is enabled. 132 MessagePropertySenderID MessageProperty = "solace.messaging.message.sender-id" 133 ) 134