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

Add DeleteRecords operation to Broker #1027

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

ongardie-ebay
Copy link
Contributor

I added the DeleteRecords operation. Hope it's welcome.

One thing I wasn't sure about is how you'd want the request struct to look. The current map in DeleteRecordsRequestTopic doesn't allow much room for expansion without breaking users. Is that OK?

@ongardie-ebay
Copy link
Contributor Author

Here's some sample code if you're interested in taking this for a spin:

	broker := sarama.NewBroker("localhost:9092")
	config := sarama.NewConfig()
	config.Version = sarama.V0_11_0_0
	err := broker.Open(config)
	if err != nil {
		panic(err)
	}

	request := sarama.DeleteRecordsRequest{
		Topics: map[string]*sarama.DeleteRecordsRequestTopic{
			"bar": &sarama.DeleteRecordsRequestTopic{
				PartitionOffsets: map[int32]int64{
					0: 2,
					1: 2,
				},
			},
			"foo": &sarama.DeleteRecordsRequestTopic{
				PartitionOffsets: map[int32]int64{
					0: 0,
					1: 2,
				},
			},
		},
	}
	response, err := broker.DeleteRecords(&request)
	if err != nil {
		panic(err)
	}

	fmt.Printf("response:\n")
	for topic, detail := range response.Topics {
		fmt.Printf("topic %v:\n", topic)
		for partition, pdetail := range detail.Partitions {
			errStr := "none"
			if pdetail.Err != 0 {
				errStr = fmt.Sprintf("'%s'", pdetail.Err.Error())
			}
			fmt.Printf("  partition %v: lowWatermark=%v, err=%v\n",
				partition, pdetail.LowWatermark, errStr)
		}
	}

@ongardie-ebay
Copy link
Contributor Author

Rebased onto current master, fixing trivial conflict in requests.go.

@eapache
Copy link
Contributor

eapache commented Feb 13, 2018

Thanks! Sorry it took me a while to get to this.

@eapache eapache merged commit b9cbd15 into IBM:master Feb 13, 2018
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

Successfully merging this pull request may close these issues.

2 participants