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 message 18 19 import ( 20 "time" 21 22 "solace.dev/go/messaging/pkg/solace/message/sdt" 23 ) 24 25 // Message represents the common functionality between an Inbound and Outbound message. 26 type Message interface { 27 // Message is of type Disposable. If the message has any underlying resources from the backing 28 // messaging implementation, these can be freed using Disposable.Dispose(). If Disposable.Dispose() 29 // is not called on the Message, finalizers attempt to clean up any underlying resources. 30 // Calling Dispose() is optional, but is recommended because it improves garbage collection performance. 31 // After Disposable.Dispose() is called, Message is considered unusable and all any subsequent function calls 32 // return nil or empty data. 33 Disposable 34 35 // GetProperties returns a map of user properties. 36 GetProperties() sdt.Map 37 38 // GetProperty returns the user property at the given key, and a boolean indicating if its present. 39 // Will return nil if not found. Property may be present and set to nil. 40 GetProperty(key string) (value sdt.Data, ok bool) 41 42 // HasProperty return whether a user property is present in Message. 43 HasProperty(key string) bool 44 45 // GetPayloadAsBytes attempts to get the payload of the message as a byte array. 46 // This function return bytes containing the byte array and an ok flag indicating if it was 47 // successful. If the content is not accessible in byte array form, an empty slice is 48 // returned and the ok flag is false. 49 GetPayloadAsBytes() (bytes []byte, ok bool) 50 51 // GetPayloadAsString attempts to get the payload of the message as a string. 52 // This function returns a string containing the data stored in the message and an ok flag 53 // indicating if it was successful. If the content is not accessible in string form, 54 // an empty string is returned and the ok flag is false. 55 GetPayloadAsString() (str string, ok bool) 56 57 // GetPayloadAsMap attempts to get the payload of the message as an SDTMap. 58 // This function returns a SDTMap instance containing the data stored in the message and 59 // an ok indicating if it was success. If the content is not accessible in SDTMap 60 // form, sdtMap is nil and ok is false. 61 GetPayloadAsMap() (sdtMap sdt.Map, ok bool) 62 63 // GetPayloadAsStream attempts to get the payload of the message as an SDTStream. 64 // This function returns a SDTStream instance containing the data stored in the message and 65 // an ok indicating if it was success. If the content is not accessible in SDTStream 66 // form, sdtStream is nil and ok is false. 67 GetPayloadAsStream() (sdtStream sdt.Stream, ok bool) 68 69 // GetCorrelationID returns the correlation ID of the message. 70 // If not present, the id argument is an empty string and ok is false. 71 GetCorrelationID() (id string, ok bool) 72 73 // GetExpiration returns the expiration time of the message. 74 // The expiration time is UTC time of when the message was discarded or 75 // moved to the Dead Message Queue by the broker. 76 // A value of zero (as determined by time.isZero()) indicates that the 77 // message never expires. The default value is zero. 78 GetExpiration() time.Time 79 80 // GetSequenceNumber returns the sequence number of the message. 81 // Sequence numbers may be set by the publisher applications or 82 // automatically generated by the publisher APIs. The sequence number 83 // is carried in the Message metadata in addition to the payload, and 84 // can be retrieved by consumer applications. Returns a positive 85 // sequenceNumber if set, otherwise ok is false if priority is not set. 86 GetSequenceNumber() (sequenceNumber int64, ok bool) 87 88 // GetPriority returns the priority value. Valid priorities range from 89 // 0 (lowest) to 255 (highest). Returns the priority, otherwise ok is false if priority is not set. 90 GetPriority() (priority int, ok bool) 91 92 // GetHTTPContentType returns the HTTP content-type set on the message. 93 // If not set, returns an empty string and ok is false. 94 GetHTTPContentType() (contentType string, ok bool) 95 96 // GetHTTPContentEncoding returns the HTTP content encoding set on the message. 97 // If not set, returns an empty string and ok is false. 98 GetHTTPContentEncoding() (contentEncoding string, ok bool) 99 100 // GetApplicationMessageID returns the Application Message ID of the message. 101 // This value is used by applications only and is passed through the API unmodified. 102 // If not set, returns an empty string and ok is false. 103 GetApplicationMessageID() (applicationMessageID string, ok bool) 104 105 // GetApplicationMessageType returns the Application Message Type of the message. 106 // This value is used by applications only and is passed through the API unmodified. 107 // If not set, returns an empty string and ok is false. 108 GetApplicationMessageType() (applicationMessageType string, ok bool) 109 110 // GetClassOfService returns the class of service of the message. Class of Service is 111 // represented by an integer with: 112 // 0 | COS_1 113 // 1 | COS_2 114 // 2 | COS_3 115 GetClassOfService() (cos int) 116 117 // String implements fmt.Stringer. Prints the message as a string. A truncated response 118 // may be returned when large payloads or properties are attached. 119 String() string 120 } 121