1 // pubsubplus-go-client 2 // 3 // Copyright 2021-2025 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/resource" 25 ) 26 27 // The DirectMessageReceiver is used to receive direct messages. 28 type DirectMessageReceiver interface { 29 MessageReceiver // Include all functionality of MessageReceiver. 30 ReceiverCacheRequests 31 32 // StartAsyncCallback starts the DirectMessageReceiver asynchronously. 33 // Calls the callback when started with an error if one occurred, otherwise nil 34 // if successful. 35 StartAsyncCallback(callback func(DirectMessageReceiver, error)) 36 37 // TerminateAsyncCallback terminates the DirectMessageReceiver asynchronously. 38 // Calls the callback when terminated with nil if successful or an error if 39 // one occurred. If gracePeriod is less than 0, the function will wait indefinitely. 40 TerminateAsyncCallback(gracePeriod time.Duration, callback func(error)) 41 42 // ReceiveAsync registers a callback to be called when new messages 43 // are received. Returns an error if one occurred while registering the callback. 44 // If a callback is already registered, it will be replaced by the specified 45 // callback. 46 ReceiveAsync(callback MessageHandler) error 47 48 // ReceiveMessage receives a inbound message synchronously from the receiver. 49 // Returns an error if the receiver has not started, or has already terminated. 50 // ReceiveMessage waits until the specified timeout to receive a message, or will wait 51 // forever if the timeout specified is a negative value. If a timeout occurs, a solace.TimeoutError 52 // is returned. 53 ReceiveMessage(timeout time.Duration) (received message.InboundMessage, err error) 54 } 55 56 // DirectMessageReceiverBuilder allows for configuration of DirectMessageReceiver instances. 57 type DirectMessageReceiverBuilder interface { 58 // Build creates a DirectMessageReceiver with the specified properties. 59 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided. 60 Build() (messageReceiver DirectMessageReceiver, err error) 61 // BuildWithShareName creates DirectMessageReceiver with the specified ShareName. 62 // Returns solace/errors.*InvalidConfigurationError if an invalid configuration is provided 63 // or the specified ShareName is invalid. 64 BuildWithShareName(shareName *resource.ShareName) (messageReceiver DirectMessageReceiver, err error) 65 // OnBackPressureDropLatest configures the receiver with the specified buffer size. If the buffer 66 // is full and a message arrives, the incoming message is discarded. 67 // A buffer of the given size will be statically allocated when the receiver is built. 68 // The bufferCapacity must be greater than or equal to 1. 69 OnBackPressureDropLatest(bufferCapacity uint) DirectMessageReceiverBuilder 70 // OnBackPressureDropOldest configures the receiver with the specified buffer size, bufferCapacity. If the buffer 71 // is full and a message arrives, the oldest message in the buffer is discarded. 72 // A buffer of the given size will be statically allocated when the receiver is built. 73 // The value of bufferCapacity must be greater than or equal to 1. 74 OnBackPressureDropOldest(bufferCapacity uint) DirectMessageReceiverBuilder 75 // WithSubscriptions sets a list of TopicSubscriptions to subscribe 76 // to when starting the receiver. This function also accepts *resource.TopicSubscription subscriptions. 77 WithSubscriptions(topics ...resource.Subscription) DirectMessageReceiverBuilder 78 // FromConfigurationProvider configures the DirectMessageReceiver with the specified properties. 79 // The built-in ReceiverPropertiesConfigurationProvider implementations include: 80 // - ReceiverPropertyMap - A map of ReceiverProperty keys to values. 81 FromConfigurationProvider(provider config.ReceiverPropertiesConfigurationProvider) DirectMessageReceiverBuilder 82 } 83