{"id":17925846,"url":"https://github.com/maxwellpeterson/kafka-websocket-shim","last_synced_at":"2026-02-09T14:34:33.402Z","repository":{"id":61623674,"uuid":"527104622","full_name":"maxwellpeterson/kafka-websocket-shim","owner":"maxwellpeterson","description":"frame Kafka protocol messages sent over TCP into WebSocket messages","archived":false,"fork":false,"pushed_at":"2022-09-28T19:20:25.000Z","size":284,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T01:31:32.256Z","etag":null,"topics":["kafka","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxwellpeterson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-21T04:26:53.000Z","updated_at":"2022-10-06T22:13:59.000Z","dependencies_parsed_at":"2022-10-20T10:00:45.452Z","dependency_job_id":null,"html_url":"https://github.com/maxwellpeterson/kafka-websocket-shim","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/maxwellpeterson%2Fkafka-websocket-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxwellpeterson%2Fkafka-websocket-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxwellpeterson%2Fkafka-websocket-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxwellpeterson%2Fkafka-websocket-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxwellpeterson","download_url":"https://codeload.github.com/maxwellpeterson/kafka-websocket-shim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245204543,"owners_count":20577370,"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":["kafka","websocket"],"created_at":"2024-10-28T20:58:08.934Z","updated_at":"2026-02-09T14:34:28.355Z","avatar_url":"https://github.com/maxwellpeterson.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kafka WebSocket Shim\n\n**Note:** This is a child project of [`kafka-worker`](https://github.com/maxwellpeterson/kafka-worker)\n\nA shim layer that enables existing Kafka clients to connect to a broker implementation running on Cloudflare Workers with minimal configuration changes. As with the parent project, this is a simple proof of concept and not intended to be used for anything serious.\n\n## Modes of Operation\n\n### Go Package\n\nFor Kafka clients written in Go, this project provides a Go package with a `net.Conn` implementation that frames Kafka protocol messages into WebSocket messages, plus a `proxy.Dialer` and `proxy.ContextDialer` implementation that creates these connections.\n\nSee [`kafka-worker-demo`](https://github.com/maxwellpeterson/kafka-worker-demo) for an example that uses this package with the [`franz-go`](https://github.com/twmb/franz-go) client.\n\n### TCP Proxy\n\nFor Kafka clients written in other languages, this project provides a standalone TCP proxy that frames Kafka protocol messages into WebSocket messages and forwards them to the broker implementation.\n\nSee [`kafka-worker-demo`](https://github.com/maxwellpeterson/kafka-worker-demo) for an example that uses the proxy with the [`kafka-python`](https://github.com/dpkp/kafka-python) client.\n\n## How It Works\n\nAll Kafka protocol messages use the following grammar (defined in the [Kafka Protocol Guide](https://kafka.apache.org/protocol.html#protocol_common)):\n\n```\nRequestOrResponse =\u003e Size (RequestMessage | ResponseMessage)\n  Size =\u003e int32\n```\n\nTo convert a continuous stream of protocol messages into discrete WebSocket messages, all we need to do is read the size of the first protocol message as a 32-bit integer `n`, read the next `n` bytes of the stream, wrap these `n + 4` bytes in a WebSocket message, and repeat the same process for the remainder of the stream. It's super simple.\n\n## Quick Start\n\n### Go Package\n\n```shell\ngo get github.com/maxwellpeterson/kafka-websocket-shim/pkg/shim\n```\n\n### TCP Proxy (From Source)\n\nThis method requires a local installation of Go.\n\n```shell\ngit clone https://github.com/maxwellpeterson/kafka-websocket-shim.git\ncd kafka-websocket-shim\ngo run cmd/kafka-websocket-proxy/main.go\n```\n\n### TCP Proxy (`go install`)\n\nThis method requires a local installation of Go, and assumes that `GOPATH/bin` is part of `PATH`.\n\n```shell\ngo install github.com/maxwellpeterson/kafka-websocket-shim/cmd/kafka-websocket-proxy\nkafka-websocket-proxy\n```\n\n### TCP Proxy (Docker)\n\nThis method requires a local installation of Docker.\n\n```shell\ndocker run --rm --publish 8080:8080 ghcr.io/maxwellpeterson/kafka-websocket-proxy:main -broker=mybroker.workers.dev:443 -tls\n```\n\nTo connect to a local instance of `kafka-worker`, it is recommended to run `kafka-worker` in a container and create a shared network for the proxy and broker. Using Docker Compose makes this setup easy, see [`kafka-worker-demo`](https://github.com/maxwellpeterson/kafka-worker-demo) for examples.\n\n## Map\n\n![kafka worker map](map.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxwellpeterson%2Fkafka-websocket-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxwellpeterson%2Fkafka-websocket-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxwellpeterson%2Fkafka-websocket-shim/lists"}