Skip to content

Commit

Permalink
Merge pull request #118 from kpn/fix/example-docs
Browse files Browse the repository at this point in the history
docs: improve example
  • Loading branch information
woile authored Jul 20, 2023
2 parents ae87199 + b48fcb8 commit bab1531
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ services:
zookeeper:
image: "confluentinc/cp-zookeeper:7.0.0"
hostname: zookeeper
container_name: zookeeper
container_name: kstream_zookeeper
ports:
- 32181:32181
environment:
- ZOOKEEPER_CLIENT_PORT=32181
kafka:
image: confluentinc/cp-kafka:7.0.0
hostname: kafka
container_name: kafka
container_name: kstream_kafka
ports:
- 9092:9092
- 9093:9093
Expand Down
2 changes: 1 addition & 1 deletion examples/fastapi-sse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ poetry install
INFO: 127.0.0.1:51060 - "GET /topics/local--sse/group-1/ HTTP/1.1" 200 OK
Client connected Address(host='127.0.0.1', port=51060)
```
4. From a different terminal you can send events to the topic and they should be return to the frontend via `fastapi-sse`. From the `kstreams` project root execute `./scripts/cluster/events/send local-sse`
4. From a different terminal you can send events to the topic and they should be return to the frontend via `fastapi-sse`. From the `kstreams` project root execute `./scripts/cluster/events/send local--sse`
```bash
>Hi SSE
```
Expand Down
2 changes: 1 addition & 1 deletion examples/fastapi-sse/fastapi_sse/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if __name__ == "__main__":
uvicorn.run(
app="sse.app:app",
app="fastapi_sse.app:app",
host="localhost",
port=8000,
log_level=logging.INFO,
Expand Down
18 changes: 13 additions & 5 deletions examples/fastapi-sse/fastapi_sse/streaming/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@


def stream_factory(
*, topic: str, group_id: str = None, auto_offset_reset: str = "earliest"
*, topic: str, group_id: str = None, auto_offset_reset: str = "latest"
):
@stream_engine.stream(topic, group_id=group_id, auto_offset_reset=auto_offset_reset)
async def stream(stream: Stream):
async def stream_func(stream: Stream):
async for cr in stream:
print(f"yield {cr.value}")
yield cr.value

return stream
s = Stream(
topic,
name=group_id,
func=stream_func,
config=dict(
auto_offset_reset=auto_offset_reset,
group_id=group_id,
),
)
stream_engine.add_stream(s)
return s

0 comments on commit bab1531

Please sign in to comment.