public Consumer(ClusterManager metadataManager, string groupId = null, IDeserializer <TKey> keyDeserializer = null, IDeserializer <TValue> valueDeserializer = null) { this.metadataManager = metadataManager ?? throw new ArgumentNullException(nameof(metadataManager)); this.groupId = groupId; if (keyDeserializer == null && !IntrinsicDeserializers.TryGetDeserializer(out keyDeserializer)) { throw new ArgumentException($"No deserializer found for Key ({typeof(TKey).Name})"); } if (valueDeserializer == null && !IntrinsicDeserializers.TryGetDeserializer(out valueDeserializer)) { throw new ArgumentException($"No deserializer found for Value ({typeof(TValue).Name})"); } this.keyDeserializer = keyDeserializer; this.valueDeserializer = valueDeserializer; }
public Producer(string topic, ClusterManager cluster, ISerializer <TKey> keySerializer = null, ISerializer <TValue> valueSerializer = null) { this.topic = topic; this.cluster = cluster; if (keySerializer == null && !IntrinsicSerializers.TryGetSerializer(out keySerializer)) { throw new ArgumentException($"{nameof(keySerializer)} not provided or discoverable"); } else { this.keySerializer = keySerializer; } if (valueSerializer == null && !IntrinsicSerializers.TryGetSerializer(out valueSerializer)) { throw new ArgumentException($"{nameof(valueSerializer)} not provided or discoverable"); } else { this.valueSerializer = valueSerializer; } }
public async Task <GroupAssignment> Assign(ClusterManager metadata, GroupSubscription groupSubscription) { Dictionary <string, Subscription> subscriptions = groupSubscription.groupSubscription(); var allSubscribedTopics = new HashSet <string>(); foreach (var topic in subscriptions.SelectMany(e => e.Value.Topics)) { allSubscribedTopics.Add(topic); } var partitionsPerTopic = new Dictionary <string, int>(); foreach (string topic in allSubscribedTopics) { int numPartitions = (await metadata.GetTopic(topic)).Partitions.Count; if (numPartitions > 0) { partitionsPerTopic.Add(topic, numPartitions); } else { log.debug("Skipping assignment for topic {} since no metadata is available", topic); } } Dictionary <string, List <TopicPartition> > rawAssignments = Assign(partitionsPerTopic, subscriptions); // this class maintains no user data, so just wrap the results var assignments = new Dictionary <string, Assignment>(); foreach (var assignmentEntry in rawAssignments) { assignments.Add(assignmentEntry.Key, new Assignment(0, assignmentEntry.Value, null)); } return(new GroupAssignment(assignments)); }
public TopicMetadataCache(ClusterManager metadataManager, TimeSpan timeout) { this.metadataManager = metadataManager; this.timeout = timeout; }
public TopicMetadataCache(ClusterManager metadataManager) : this(metadataManager, DefaultTimeout) { }