...

Source file src/solace.dev/go/messaging/pkg/solace/message_receiver.go

Documentation: solace.dev/go/messaging/pkg/solace

     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  	"solace.dev/go/messaging/pkg/solace/message"
    21  	"solace.dev/go/messaging/pkg/solace/resource"
    22  )
    23  
    24  // MessageReceiver represents the shared functionality between all MessageReceivers
    25  type MessageReceiver interface {
    26  	// Extend LifecycleControl for various lifecycle management functionality
    27  	LifecycleControl
    28  
    29  	// AddSubscription will subscribe to another message source on a PubSub+ Broker to receive messages from.
    30  	// Will block until subscription is added. Accepts *resource.TopicSubscription instances as the subscription.
    31  	// Returns a solace/errors.*IllegalStateError if the service is not running.
    32  	// Returns a solace/errors.*IllegalArgumentError if unsupported Subscription type is passed.
    33  	// Returns nil if successful.
    34  	AddSubscription(subscription resource.Subscription) error
    35  
    36  	// RemoveSubscription will unsubscribe from a previously subscribed message source on a broker
    37  	// such that no more messages will be received from it.
    38  	// Will block until subscription is removed.
    39  	// Accepts *resource.TopicSubscription instances as the subscription.
    40  	// Returns an solace/errors.*IllegalStateError if the service is not running.
    41  	// Returns a solace/errors.*IllegalArgumentError if unsupported Subscription type is passed.
    42  	// Returns nil if successful.
    43  	RemoveSubscription(subscription resource.Subscription) error
    44  
    45  	// AddSubscriptionAsync will subscribe to another message source on a PubSub+ Broker to receive messages from.
    46  	// Will block until subscription is added. Accepts *resource.TopicSubscription instances as the subscription.
    47  	// Returns a solace/errors.*IllegalStateError if the service is not running.
    48  	// Returns a solace/errors.*IllegalArgumentError if unsupported Subscription type is passed.
    49  	// Returns nil if successful.
    50  	AddSubscriptionAsync(subscription resource.Subscription, listener SubscriptionChangeListener) error
    51  
    52  	// RemoveSubscriptionAsymc will unsubscribe from a previously subscribed message source on a broker
    53  	// such that no more messages will be received from it. Will block until subscription is removed.
    54  	// Accepts *resource.TopicSubscription instances as the subscription.
    55  	// Returns an solace/errors.*IllegalStateError if the service is not running.
    56  	// Returns a solace/errors.*IllegalArgumentError if unsupported Subscription type is passed.
    57  	// Returns nil if successful.
    58  	RemoveSubscriptionAsync(subscription resource.Subscription, listener SubscriptionChangeListener) error
    59  }
    60  
    61  // SubscriptionOperation represents the operation that triggered a SubscriptionChangeListener callback
    62  type SubscriptionOperation byte
    63  
    64  const (
    65  	// SubscriptionAdded is the resulting subscription operation from AddSubscriptionAsync
    66  	SubscriptionAdded SubscriptionOperation = iota
    67  	// SubscriptionRemoved is the resulting subscription operation from RemoveSubscription
    68  	SubscriptionRemoved
    69  )
    70  
    71  // SubscriptionChangeListener is a callback that can be set on async subscription operations
    72  // that allows for handling of success or failure. The callback will be passed the subscription
    73  // in question, the operation (either SubscriptionAdded or SubscriptionRemoved), and the error
    74  // or nil if no error was thrown while adding the subscription.
    75  type SubscriptionChangeListener func(subscription resource.Subscription, operation SubscriptionOperation, errOrNil error)
    76  
    77  // MessageHandler is a callback that can be registered to receive messages asynchronously.
    78  type MessageHandler func(inboundMessage message.InboundMessage)
    79