faust icon indicating copy to clipboard operation
faust copied to clipboard

Starting a worker without Kafka

Open devchakraborty opened this issue 7 years ago • 6 comments

Is there a way to start a worker without needing it to bootstrap with Kafka? Basically I'd like to be able to run a worker that doesn't do anything with Kafka, but uses channels directly (and maybe other transports I implement). A simple example that I'd like to work is the following:

import faust

app = faust.App('test_app')

channel = app.channel(value_type=str)

@app.timer(interval=1)
async def publish():
    await channel.put('test')

@app.agent(channel)
async def channel_log(stream):
    async for message in stream:
        print(message)

if __name__ == "__main__":
    app.main()

devchakraborty avatar Dec 07 '18 19:12 devchakraborty

You can do this in the latest version:


import faust
from faust.app.base import BootStrategy
class App(faust.App):

    class BootStrategy(BootStrategy):
         enable_kafka = False


app = App('test_app')

ask avatar Jan 15 '19 00:01 ask

@ask 'BootStrategy' is not declared in all

zibuyu1995 avatar Jan 15 '19 03:01 zibuyu1995

@ask if enable_kafka = False run faust error: Consumer thread not yet started

code:

import faust
from faust.app.base import BootStrategy
class App(faust.App):

    class BootStrategy(BootStrategy):
         enable_kafka = False

app = App('test_app') 

faust -A app worker -l info

error mssage:

Traceback (most recent call last):
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/worker.py", line 219, in execute_from_commandline
    self.loop.run_until_complete(self._starting_fut)
  File "uvloop/loop.pyx", line 1446, in uvloop.loop.Loop.run_until_complete
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/worker.py", line 280, in start
    await super().start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 706, in start
    await self._default_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 713, in _default_start
    await self._actually_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 732, in _actually_start
    await child.maybe_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 758, in maybe_start
    await self.start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 706, in start
    await self._default_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 713, in _default_start
    await self._actually_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 732, in _actually_start
    await child.maybe_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 758, in maybe_start
    await self.start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 706, in start
    await self._default_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 713, in _default_start
    await self._actually_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/mode/services.py", line 725, in _actually_start
    await self.on_start()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/faust/tables/manager.py", line 74, in on_start
    await self._update_channels()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/faust/tables/manager.py", line 86, in _update_channels
    tp for tp in self.app.consumer.assignment()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/faust/transport/drivers/aiokafka.py", line 543, in assignment
    return self._thread.assignment()
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/faust/transport/drivers/aiokafka.py", line 660, in assignment
    return cast(Set[TP], self._ensure_consumer().assignment())
  File "/xxxxx/.virtualenvs/xxxxx/lib/python3.6/site-packages/faust/transport/drivers/aiokafka.py", line 681, in _ensure_consumer
    raise ConsumerNotStarted('Consumer thread not yet started')
faust.exceptions.ConsumerNotStarted: Consumer thread not yet started

zibuyu1995 avatar Jan 15 '19 06:01 zibuyu1995

The above example still produces exactly the same error: Consumer thread not yet started error in fast 1.5.2 (pull request #278 is included in that release) and it did not resolve the issue.

groundnuty avatar Mar 29 '19 00:03 groundnuty

I just tried the example above and the error Consumer thread not yet started still occurs (1.9.0). Any reason in particular this issue has been closed?

stereobutter avatar Jan 13 '20 10:01 stereobutter

Maybe try

import faust
from faust.app.base import BootStrategy

class App(faust.App):

    producer_only = True

    class BootStrategy(BootStrategy):
        enable_kafka = False

app = App('test_app') 

allisonwang avatar Mar 17 '20 04:03 allisonwang