...

Source file src/solace.dev/go/messaging/pkg/solace/config/message_receiver_strategies.go

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

     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 config
    18  
    19  import (
    20  	"time"
    21  
    22  	"solace.dev/go/messaging/pkg/solace/message/rgmid"
    23  )
    24  
    25  // ReplayStrategy is an interface for Message Replay strategies.
    26  // Message Replay lets applications retrieve messages from an event
    27  // broker hours or even days after those messages were first received
    28  // by the broker.
    29  type ReplayStrategy struct {
    30  	strategy string
    31  	data     interface{}
    32  }
    33  
    34  // GetStrategy returns the strategy type stored in this ReplayStrategy.
    35  func (strategy ReplayStrategy) GetStrategy() string {
    36  	return strategy.strategy
    37  }
    38  
    39  // GetData returns the additional data, if applicable, stored with the strategy.
    40  // For example, for time based replay this contains the start date.
    41  func (strategy ReplayStrategy) GetData() interface{} {
    42  	return strategy.data
    43  }
    44  
    45  // ReplayStrategyAllMessages sets the strategy to replaying all
    46  // messages stored on the broker's replay log.
    47  func ReplayStrategyAllMessages() ReplayStrategy {
    48  	return ReplayStrategy{
    49  		strategy: PersistentReplayAll,
    50  		data:     nil,
    51  	}
    52  }
    53  
    54  // ReplayStrategyTimeBased sets the strategy to replay
    55  // all messages stored on the broker's replay log dated at or
    56  // after the specified replayDate. Note that the replayDate given
    57  // should be set to the correct timezone from which replay is
    58  // meant to begin. See time.Date for the appropriate
    59  // configuration of a timezone aware time.Time value.
    60  func ReplayStrategyTimeBased(replayDate time.Time) ReplayStrategy {
    61  	return ReplayStrategy{
    62  		strategy: PersistentReplayTimeBased,
    63  		data:     replayDate,
    64  	}
    65  }
    66  
    67  // ReplayStrategyReplicationGroupMessageID sets the strategy
    68  // to replay all messages stored on the broker's replay log
    69  // received at or after the specified messageID. Returns the constructed
    70  // ReplayStrategy.
    71  // Valid Replication Group Message IDs take the form
    72  //
    73  //	rmid1:xxxxx-xxxxxxxxxxx-xxxxxxxx-xxxxxxxx
    74  //
    75  // where x is a valid hexadecimal digit.
    76  func ReplayStrategyReplicationGroupMessageID(replicationGroupMessageID rgmid.ReplicationGroupMessageID) ReplayStrategy {
    77  	return ReplayStrategy{
    78  		strategy: PersistentReplayIDBased,
    79  		data:     replicationGroupMessageID,
    80  	}
    81  }
    82