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 solace 18 19 import ( 20 "time" 21 22 "solace.dev/go/messaging/pkg/solace/config" 23 "solace.dev/go/messaging/pkg/solace/message" 24 "solace.dev/go/messaging/pkg/solace/message/sdt" 25 ) 26 27 // OutboundMessageBuilder allows construction of messages to be sent. 28 type OutboundMessageBuilder interface { 29 // Build creates an OutboundMessage instance based on the configured properties. 30 // Accepts additional configuration providers to apply only to the built message, with the 31 // last in the list taking precedence. 32 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 33 Build(additionalConfiguration ...config.MessagePropertiesConfigurationProvider) (message.OutboundMessage, error) 34 // BuildWithByteArrayPayload creates a message with a byte array payload. 35 // Accepts additional configuration providers to apply only to the built message, with the 36 // last in the list taking precedence. 37 // Returns the built message, otherwise an error if one occurred. 38 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 39 BuildWithByteArrayPayload(payload []byte, additionalConfiguration ...config.MessagePropertiesConfigurationProvider) (message message.OutboundMessage, err error) 40 // BuildWithStringPayload builds a new message with a string payload. 41 // Accepts additional configuration providers to apply only to the built message, with the 42 // last in the list taking precedence. 43 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 44 BuildWithStringPayload(payload string, additionalConfiguration ...config.MessagePropertiesConfigurationProvider) (message message.OutboundMessage, err error) 45 // BuildWithMapPayload builds a new message with a SDTMap payload. 46 // Accepts additional configuration providers to apply only to the built message, with the 47 // last in the list taking precedence. 48 // If invalid data, ie. data not allowed as SDTData, is found in the 49 // map, this function will return a nil OutboundMessage and an error. 50 // Returns a solace/errors.*IllegalArgumentError if an invalid payload is specified. 51 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 52 BuildWithMapPayload(payload sdt.Map, additionalConfiguration ...config.MessagePropertiesConfigurationProvider) (message message.OutboundMessage, err error) 53 // BuildWithStreamPayload builds a new message with a SDTStream payload. 54 // Accepts additional configuration providers to apply only to the built message, with the 55 // last in the list taking precedence. 56 // If invalid data, ie. data not allowed as SDTData, is found in the 57 // stream, this function returns a nil OutboundMessage and an error. 58 // Returns a solace/errors.*IllegalArgumentError if an invalid payload is specified. 59 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 60 BuildWithStreamPayload(payload sdt.Stream, additionalConfiguration ...config.MessagePropertiesConfigurationProvider) (message message.OutboundMessage, err error) 61 // FromConfigurationProvider sets the given message properties to the resulting message. 62 // Both Solace defined config.MessageProperty keys as well as arbitrary user-defined 63 // property keys are accepted. If using custom defined properties, the date type can be 64 // any of sdt.Data supported types. 65 FromConfigurationProvider(properties config.MessagePropertiesConfigurationProvider) OutboundMessageBuilder 66 // WithProperty sets an individual message property on the resulting message. 67 // Both Solace defined config.MessageProperty keys as well as arbitrary user-defined 68 // property keys are accepted. If using custom defined properties, the date type can be 69 // any of sdt.Data supported types. 70 WithProperty(propertyName config.MessageProperty, propertyValue interface{}) OutboundMessageBuilder 71 // WithExpiration sets the message expiration time to the given time. 72 WithExpiration(t time.Time) OutboundMessageBuilder 73 // WithHTTPContentHeader sets the specified HTTP content-header on the message. 74 WithHTTPContentHeader(contentType, contentEncoding string) OutboundMessageBuilder 75 // WithPriority sets the priority of the message, where the priority is a value between 0 (lowest) and 255 (highest). 76 WithPriority(priority int) OutboundMessageBuilder 77 // WithApplicationMessageId sets the application message ID of the message. It is carried in the message metadata 78 // and is used for application to application signaling. 79 WithApplicationMessageID(messageID string) OutboundMessageBuilder 80 // WithApplicationMessageType sets the application message type for a message. It is carried in the message metadata 81 // and is used for application to application signaling. 82 WithApplicationMessageType(messageType string) OutboundMessageBuilder 83 // WithSequenceNumber sets the sequence number for the message. The sequence number is carried in the message metadata 84 // and is used for application to application signaling. 85 WithSequenceNumber(sequenceNumber uint64) OutboundMessageBuilder 86 // WithSenderID sets the sender ID for a message from a string. If config.ServicePropertyGenerateSenderID is enabled on 87 // the messaging service, then passing a string to this method will override the API generated sender ID. 88 WithSenderID(senderID string) OutboundMessageBuilder 89 // WithCorrelationID sets the correlation ID for the message. The correlation ID is user-defined and carried end-to-end. 90 // It can be matched in a selector, but otherwise is not relevant to the event broker. The correlation ID may be used 91 // for peer-to-peer message synchronization. In JMS applications, this field is carried as the JMSCorrelationID Message 92 // Header Field. 93 WithCorrelationID(correlationID string) OutboundMessageBuilder 94 } 95