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