Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to persist and start from a Offset #108

Open
marcofranssen opened this issue Jan 18, 2017 · 1 comment
Open

Best way to persist and start from a Offset #108

marcofranssen opened this issue Jan 18, 2017 · 1 comment

Comments

@marcofranssen
Copy link

I am currently struggling to find the best way to persist the current offset and how I can now if I should keep an offset for various partitions.

Furthermore I have the same question when starting the consumption of messages. How do I know which Partition I should start.

My publisher uses no key, so that means it is doing RoundRobin if I am not mistaking.

When I create a consumer I can provide the OffsetPosition, but I'm not sure how I can know what is the correct Offset and partition to use.

This is basically my consumer code atm.

        public Task Run(CancellationToken token)
        {
            return Task.Run(() =>
            {
                var offset = ReadPersistedOffset();
                using (var consumer = CreateConsumer(_topic, offset))
                {
                    while (!token.IsCancellationRequested)
                    {
                        foreach (var message in consumer.Consume())
                        {
                            var eventJson = GetJson(message.Value);
                            var @event = GetPayload(eventJson);
                            DispatchToSubscriber(@event);
                            PersistOffset(message.Meta);
                        }
                    }
                }
            });
        }

So is it enough to just perist the message meta propery? Offset and PartitionId, should I keep a dictionary of partitions and offsets?

How do I create the consumer based on the offset? Should I start consuming form multiple partitions? Can this actually happen?

@ashishbhatia22
Copy link

Hi,
Did you find a solution to this problem? I see that offset and partition are managed by zookeeper. If a consumer wants to replay all messages for a given date, is there a recommended solution to handle that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants