Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve example #118

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading