github.com/Axway/agent-sdk@v1.1.101/pkg/agent/stream/options.go (about)

     1  package stream
     2  
     3  import (
     4  	agentcache "github.com/Axway/agent-sdk/pkg/agent/cache"
     5  	"github.com/Axway/agent-sdk/pkg/agent/events"
     6  	management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
     7  	"github.com/Axway/agent-sdk/pkg/harvester"
     8  	"github.com/Axway/agent-sdk/pkg/util"
     9  	hc "github.com/Axway/agent-sdk/pkg/util/healthcheck"
    10  )
    11  
    12  // StreamerOpt func for setting fields on the StreamerClient
    13  type StreamerOpt func(client *StreamerClient)
    14  
    15  // WithWatchTopic sets the watch topic
    16  func WithWatchTopic(wt *management.WatchTopic) StreamerOpt {
    17  	return func(client *StreamerClient) {
    18  		client.wt = wt
    19  		client.topicSelfLink = wt.GetSelfLink()
    20  	}
    21  }
    22  
    23  // WithCacheManager sets a cache manager
    24  func WithCacheManager(cache agentcache.Manager) StreamerOpt {
    25  	return func(client *StreamerClient) {
    26  		client.cacheManager = cache
    27  	}
    28  }
    29  
    30  // WithUserAgent sets the userAgent for gRPC stream
    31  func WithUserAgent(userAgent string) StreamerOpt {
    32  	return func(client *StreamerClient) {
    33  		client.watchCfg.UserAgent = userAgent
    34  	}
    35  }
    36  
    37  // WithHarvester configures the streaming client to use harvester for syncing initial events
    38  func WithHarvester(hClient harvester.Harvest, sequence events.SequenceProvider) StreamerOpt {
    39  	return func(client *StreamerClient) {
    40  		client.sequence = sequence
    41  		client.harvester = hClient
    42  	}
    43  }
    44  
    45  // WithEventSyncError sets the callback func to run when there is an error syncing events
    46  func WithEventSyncError(cb func()) StreamerOpt {
    47  	return func(client *StreamerClient) {
    48  		client.onEventSyncError = cb
    49  	}
    50  }
    51  
    52  // WithOnStreamConnection func to execute when a connection to central is made
    53  func WithOnStreamConnection() StreamerOpt {
    54  	return func(pc *StreamerClient) {
    55  		pc.onStreamConnection = func() {
    56  			hc.RegisterHealthcheck(util.AmplifyCentral, util.CentralHealthCheckEndpoint, pc.Healthcheck)
    57  		}
    58  	}
    59  }