Skip to content

Instantly share code, notes, and snippets.

@chobeat
Created March 31, 2019 10:16
Show Gist options
  • Save chobeat/50e2a91dba6e90f4debd515a2cfbfdfc to your computer and use it in GitHub Desktop.
Save chobeat/50e2a91dba6e90f4debd515a2cfbfdfc to your computer and use it in GitHub Desktop.
import faust
app = faust.App("debug", broker="localhost:9092")
def a(mess):
print("I'm a")
print(mess)
def b(mess):
print("I'm b")
print(mess)
def c(mess):
print("I'm c")
print(mess)
for transformation, topic in [(a,"a"),(b,"b"),(c,"c")]:
async def _func(messages):
async for message in messages:
transformation(message)
_func.__name__="transformation_"+topic
app.agent(app.topic(topic,
value_serializer="raw"), name="transformation_"+topic)(_func)
def main():
app.main()
@chobeat
Copy link
Author

chobeat commented Mar 31, 2019

➜ faust -A main send a "test"
{"topic": "a", "partition": 0, "topic_partition": ["a", 0], "offset": 0, "timestamp": 1554027210355, "timestamp_type": 0}
➜ faust -A main send c "test"
{"topic": "c", "partition": 0, "topic_partition": ["c", 0], "offset": 0, "timestamp": 1554027297028, "timestamp_type": 0}
➜ faust -A main send b "test"
{"topic": "b", "partition": 0, "topic_partition": ["b", 0], "offset": 0, "timestamp": 1554027301971, "timestamp_type": 0}

The agents
│ @transformation_a │ a     │ <N/A> │
│ @transformation_b │ b     │ <N/A> │
│ @transformation_c │ c     │ <N/A> │

The console log:

[2019-03-31 12:13:30,661: WARNING]: I'm c 
[2019-03-31 12:13:30,662: WARNING]: b'test' 
[2019-03-31 12:14:57,623: WARNING]: I'm c 
[2019-03-31 12:14:57,624: WARNING]: b'test' 
[2019-03-31 12:15:02,785: WARNING]: I'm c 
[2019-03-31 12:15:02,785: WARNING]: b'test' ```

@aron-bordin
Copy link

Hi! have you fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment