github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/msg/topic/types.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package topic 22 23 import ( 24 "github.com/m3db/m3/src/cluster/client" 25 "github.com/m3db/m3/src/cluster/kv" 26 "github.com/m3db/m3/src/cluster/services" 27 ) 28 29 // Topic defines the topic of messages. 30 type Topic interface { 31 // Name returns the name of the topic. 32 Name() string 33 34 // SetName sets the name of the topic. 35 SetName(value string) Topic 36 37 // NumberOfShards returns the total number of shards of the topic. 38 NumberOfShards() uint32 39 40 // SetNumberOfShards sets the total number of shards of the topic. 41 SetNumberOfShards(value uint32) Topic 42 43 // ConsumerServices returns the consumers of the topic. 44 ConsumerServices() []ConsumerService 45 46 // SetConsumerServices sets the consumers of the topic. 47 SetConsumerServices(value []ConsumerService) Topic 48 49 // Version returns the version of the topic. 50 Version() int 51 52 // SetVersion sets the version of the topic. 53 SetVersion(value int) Topic 54 55 // AddConsumerService adds a consumer to the topic. 56 AddConsumerService(value ConsumerService) (Topic, error) 57 58 // RemoveConsumerService removes a consumer from the topic. 59 RemoveConsumerService(value services.ServiceID) (Topic, error) 60 61 // UpdateConsumerService updates a consumer in the topic. 62 UpdateConsumerService(value ConsumerService) (Topic, error) 63 64 // String returns the string representation of the topic. 65 String() string 66 67 // Validate validates the topic. 68 Validate() error 69 } 70 71 // ConsumerService is a service that consumes the messages in a topic. 72 type ConsumerService interface { 73 // ServiceID returns the service id of the consumer service. 74 ServiceID() services.ServiceID 75 76 // SetServiceID sets the service id of the consumer service. 77 SetServiceID(value services.ServiceID) ConsumerService 78 79 // ConsumptionType returns the consumption type of the consumer service. 80 ConsumptionType() ConsumptionType 81 82 // SetConsumptionType sets the consumption type of the consumer service. 83 SetConsumptionType(value ConsumptionType) ConsumerService 84 85 // MessageTTLNanos returns ttl for each message in nanoseconds. 86 MessageTTLNanos() int64 87 88 // SetMessageTTLNanos sets ttl for each message in nanoseconds. 89 SetMessageTTLNanos(value int64) ConsumerService 90 91 // String returns the string representation of the consumer service. 92 String() string 93 } 94 95 // Watch watches the updates of a topic. 96 type Watch interface { 97 // C returns the notification channel. 98 C() <-chan struct{} 99 100 // Get returns the latest version of the topic. 101 Get() (Topic, error) 102 103 // Close stops watching for topic updates. 104 Close() 105 } 106 107 // Service provides accessibility to topics. 108 type Service interface { 109 // Get returns the topic and version for the given name. 110 Get(name string) (Topic, error) 111 112 // CheckAndSet sets the topic for the name if the version matches. 113 CheckAndSet(t Topic, version int) (Topic, error) 114 115 // Delete deletes the topic with the name. 116 Delete(name string) error 117 118 // Watch returns a topic watch. 119 Watch(name string) (Watch, error) 120 } 121 122 // ServiceOptions configures the topic service. 123 type ServiceOptions interface { 124 // ConfigService returns the client of config service. 125 ConfigService() client.Client 126 127 // SetConfigService sets the client of config service. 128 SetConfigService(c client.Client) ServiceOptions 129 130 // KVOverrideOptions returns the override options for KV store. 131 KVOverrideOptions() kv.OverrideOptions 132 133 // SetKVOverrideOptions sets the override options for KV store. 134 SetKVOverrideOptions(value kv.OverrideOptions) ServiceOptions 135 } 136 137 // ConsumptionType defines how the consumer consumes messages. 138 type ConsumptionType string 139 140 const ( 141 // Unknown is the unknown consumption type. 142 Unknown ConsumptionType = "unknown" 143 144 // Shared means the messages for each shard will be 145 // shared by all the responsible instances. 146 Shared ConsumptionType = "shared" 147 148 // Replicated means the messages for each shard will be 149 // replicated to all the responsible instances. 150 Replicated ConsumptionType = "replicated" 151 )