Skip to content

Commit a3b4f42

Browse files
committed
Add publisher
1 parent f75d6b4 commit a3b4f42

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/sasquatchbackpack/sasquatch.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ async def direct_connect(self) -> None:
223223
"""
224224
config = KafkaConnectionSettings()
225225
kafka_broker = KafkaBroker(**config.to_faststream_params())
226+
prepared_publisher = kafka_broker.publisher(self.source.topic_name)
226227

227228
records = self._get_source_records()
228229
if records is None:
@@ -231,7 +232,13 @@ async def direct_connect(self) -> None:
231232
return
232233

233234
payload = json.dumps({"value_schema": self.schema, "records": records})
234-
await kafka_broker.publish(payload, self.source.topic_name)
235+
await prepared_publisher.publish(
236+
payload,
237+
headers={
238+
"Content-Type": "application/vnd.kafka.avro.v2+json",
239+
"Accept": "application/vnd.kafka.v2+json",
240+
},
241+
)
235242

236243
def post(self) -> tuple[str, list]:
237244
"""Assemble schema and payload from the given source, then

src/sasquatchbackpack/sources/usgs/commands.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import UTC, datetime, timedelta
55

66
import click
7-
import nest_asyncio
87

98
from sasquatchbackpack import sasquatch
109
from sasquatchbackpack.sources.usgs import scripts
@@ -201,7 +200,6 @@ def usgs_earthquake_data(
201200
click.echo("Post mode enabled: Sending data...")
202201
click.echo(f"Querying redis at {backpack_dispatcher.redis.address}")
203202

204-
nest_asyncio.apply()
205203
loop = asyncio.new_event_loop()
206204
loop.run_until_complete(backpack_dispatcher.direct_connect())
207205

0 commit comments

Comments
 (0)