{"id":17963984,"url":"https://github.com/teivah/resequencer","last_synced_at":"2026-02-25T15:04:16.834Z","repository":{"id":57651493,"uuid":"449430301","full_name":"teivah/resequencer","owner":"teivah","description":"Resequencer library","archived":false,"fork":false,"pushed_at":"2022-01-18T20:37:28.000Z","size":155,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T08:55:20.427Z","etag":null,"topics":["eip","go","golang","library"],"latest_commit_sha":null,"homepage":"https://www.enterpriseintegrationpatterns.com/Resequencer.html","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teivah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-18T20:04:50.000Z","updated_at":"2023-06-01T09:46:53.000Z","dependencies_parsed_at":"2022-09-26T20:30:58.362Z","dependency_job_id":null,"html_url":"https://github.com/teivah/resequencer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fresequencer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fresequencer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fresequencer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fresequencer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teivah","download_url":"https://codeload.github.com/teivah/resequencer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240890436,"owners_count":19874000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eip","go","golang","library"],"created_at":"2024-10-29T11:46:14.972Z","updated_at":"2025-10-28T20:06:15.668Z","avatar_url":"https://github.com/teivah.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resequencer\n\n![CI](https://github.com/teivah/resequencer/actions/workflows/ci.yml/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/teivah/resequencer)](https://goreportcard.com/report/github.com/teivah/resequencer)\n\nA Go resequencer\n\n## Introduction\n\n`resequencer` is a Go library that implements the [resequencer pattern](https://www.enterpriseintegrationpatterns.com/Resequencer.html).\n\nOne use case, for example, is when using Sarama with a consumer group, and we distribute each message to a set of workers. If we want to make sure the offsets are committed in sequence, we can use a resequencer per partition.\n\n## How to Use\n\nFirst, we need to create a new `Handler`. Then we have to use the two methods:\n* `Push` to add new sequence IDs\n* `Messages` that returns a `\u003c-chan []int` that contains the ordered sequence IDs\n\n```go\nctx, cancel := context.WithCancel(context.Background())\nhandler := resequencer.NewHandler(ctx, -1) // Create a resequencer and initialize the first sequence ID to -1\n\nmax := 10\nfor i := 0; i \u003c max; i++ {\n\ti := i\n\tgo func() {\n\t\thandler.Push(i) // Push a new sequence ID\n\t}()\n}\n\nfor sequenceIDs := range handler.Messages() { // Read all the sequence IDs (sequenceIDs is an []int)\n\tfor _, sequenceID := range sequenceIDs {\n\t\tfmt.Println(sequenceID)\n\t\tif sequenceID == max-1 {\n\t\t\tcancel()\n\t\t\treturn\n\t\t}\n\t}\n}\n```\n\nIt will output the sequence IDs in order, regardless of the goroutines execution:\n\n```\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteivah%2Fresequencer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteivah%2Fresequencer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteivah%2Fresequencer/lists"}