Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to integrate celery with Kafka

I want to introduce multiprocessing in my code using celery. But currently my queue implementation is in Kafka.

Currently celery website mentions of only these 4 brokers: http://docs.celeryproject.org/en/master/getting-started/brokers/index.html#broker-overview

Is it possible to integrate Celery with Kafka something similar to RabbitMQ mentioned below:

from celery import Celery
app = Celery('tasks', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
    return x + y
like image 961
ashdnik Avatar asked Aug 21 '17 09:08

ashdnik


People also ask

What is difference between Kafka and Celery?

Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well. On the other hand, Kafka is detailed as "Distributed, fault tolerant, high throughput pub-sub messaging system".

Can I use Kafka with python?

Confluent develops and maintains confluent-kafka-python on GitHub, a Python Client for Apache Kafka® that provides a high-level Producer, Consumer and AdminClient compatible with all Kafka brokers >= v0. 8, Confluent Cloud and Confluent Platform.

Does DoorDash use Kafka?

DoorDash heavily relies on the Infrastructure-As-Code principle and most of the resource creation, from Kafka topic to service configurations, involves pull requests to different terraform repositories.


2 Answers

There was discussion on having kafka as broker for celery, And there is a partial implementation of it. I hope this helps you

https://github.com/celery/kombu/issues/301

Looks like it will be available this Oct 31 or so.

https://github.com/celery/kombu/milestone/2

like image 94
user3382968 Avatar answered Sep 17 '22 12:09

user3382968


As you are searching for multiprocessing solution for Kafka I would recommend to take a look at Faust library.

Here is an example (very close to yours) in comparison with Celery:

https://faust.readthedocs.io/en/latest/playbooks/vscelery.html

import faust

app = faust.App('myapp', broker='kafka://')

@app.agent()
async def add(stream):
    async for op in stream:
        yield op.x + op.y

Also one of the creators of Faust is the author of Celery.

I am telling that because at this moment already 7 years have passed since the creation of the ticket mentioned by @user3382968, and still without progress.

like image 27
vilozio Avatar answered Sep 18 '22 12:09

vilozio