{"id":15713553,"url":"https://github.com/bt-opensource/crafka","last_synced_at":"2025-08-01T01:12:31.938Z","repository":{"id":212077748,"uuid":"730652508","full_name":"BT-OpenSource/crafka","owner":"BT-OpenSource","description":"Kafka library for Crystal. Uses librdkafka.","archived":false,"fork":false,"pushed_at":"2025-06-25T10:54:33.000Z","size":69,"stargazers_count":17,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-25T11:38:20.444Z","etag":null,"topics":["crystal","crystal-lang","kafka","librdkafka"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/BT-OpenSource.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-12T11:40:40.000Z","updated_at":"2025-06-25T10:54:36.000Z","dependencies_parsed_at":"2024-01-05T10:26:11.619Z","dependency_job_id":"11791e5f-066c-442a-9e76-d96af333de9d","html_url":"https://github.com/BT-OpenSource/crafka","commit_stats":null,"previous_names":["bt-opensource/crafka"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/BT-OpenSource/crafka","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BT-OpenSource%2Fcrafka","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BT-OpenSource%2Fcrafka/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BT-OpenSource%2Fcrafka/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BT-OpenSource%2Fcrafka/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BT-OpenSource","download_url":"https://codeload.github.com/BT-OpenSource/crafka/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BT-OpenSource%2Fcrafka/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268152112,"owners_count":24204043,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["crystal","crystal-lang","kafka","librdkafka"],"created_at":"2024-10-03T21:32:04.987Z","updated_at":"2025-08-01T01:12:31.905Z","avatar_url":"https://github.com/BT-OpenSource.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crafka\n\n[![Build Status](https://github.com/BT-OpenSource/crafka/actions/workflows/ci.yml/badge.svg)](https://github.com/BT-OpenSource/crafka/actions/workflows/ci.yml)\n[![Release](https://img.shields.io/github/v/release/BT-OpenSource/crafka)](https://github.com/BT-OpenSource/crafka/releases)\n[![License](https://img.shields.io/github/license/BT-OpenSource/crafka)](https://github.com/BT-OpenSource/crafka/blob/main/LICENSE)\n\nDetailed documentation: https://crystaldoc.info/github/BT-OpenSource/crafka/main/index.html\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  crafka:\n    github: bt-opensource/crafka\n```\n\n## Usage\n\n```crystal\nrequire \"crafka\"\n```\n\n### Producing\n```crystal\nproducer = Kafka::Producer.new({\"bootstrap.servers\" =\u003e \"localhost:9092\", \"broker.address.family\" =\u003e \"v4\"})\nproducer.produce(topic: \"topic_name\", payload: \"my message\".to_slice)\n\n# Optionally\nproducer.poll # Serves queued callbacks\nproducer.flush # Wait for outstanding produce requests to complete\n```\nAll available args to `#produce`: `topic`, `payload`, `key`, `timestamp`.\n\n#### Auto Polling\nlibrdkafka recommends that [`rd_kafka_poll`](https://github.com/confluentinc/librdkafka/blob/master/src/rdkafka.h#L3200-L3228) is called at regular intervals to serve queued callbacks. This functionality is built in to Crafka.\n\nBy default after each `#produce`, a `Kafka::Producer` will call poll if it hasn't polled in the last 5 seconds.\n\nYou can configure this with the `poll_interval` argument:\n\n```crystal\nproducer = Kafka::Producer.new(\n  {\"bootstrap.servers\" =\u003e \"localhost:9092\", \"broker.address.family\" =\u003e \"v4\"},\n  poll_interval: 30\n)\n```\n\nTo disable auto polling, set `poll_interval` to 0.\n\n#### Debug Statistics\n\nTo enable capturing of the statistics described [here](https://github.com/confluentinc/librdkafka/blob/master/STATISTICS.md) you can pass a `stats_path` argument to `Kafka::Producer.new` containing the location of a file to be written to.\n\nAlso ensure that you set the `statistics.interval.ms` in your producer config.\n\n```crystal\nproducer = Kafka::Producer.new(\n  {\"bootstrap.servers\" =\u003e \"localhost:9092\", \"broker.address.family\" =\u003e \"v4\", \"statistics.interval.ms\" =\u003e \"5000\"},\n  stats_path: \"/some/directory/librdkafka_stats.json\"\n)\n```\n\n---\n\n### Consuming\n```crystal\nconsumer = Kafka::Consumer.new({\"bootstrap.servers\" =\u003e \"localhost:9092\", \"broker.address.family\" =\u003e \"v4\", \"group.id\" =\u003e \"consumer_group_name\"})\nconsumer.subscribe(\"topic_name\")\nconsumer.each do |message|\n  # message is an instance of Kafka::Message\n  puts \"#{String.new(message.topic)} -\u003e #{String.new(message.payload)}\"\nend\nconsumer.close\n```\n\n#### Subscribing to multiple topics\n```crystal\nconsumer.subscribe(\"topic_name\", \"another_topic\", \"more_and_more\")\n\nconsumer.subscribe(\"^starts_with\") # subscribe to multiple with a regex\n```\n\n## Development\n\n### Running Tests\n```\nmake setup\ncrystal spec\n```\n\n### Releasing\n1. Update shard.yml and `src/crafka.cr` with new version number\n2. Update CHANGELOG.md with changes\n3. Commit and tag commit\n\n## Credits\nOriginally forked from: https://github.com/CloudKarafka/kafka.cr\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbt-opensource%2Fcrafka","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbt-opensource%2Fcrafka","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbt-opensource%2Fcrafka/lists"}