2025-04-24 18:57:33 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import pulsar
|
|
|
|
|
from pulsar.schema import JsonSchema
|
|
|
|
|
import base64
|
|
|
|
|
|
|
|
|
|
from trustgraph.schema import TextDocument, Metadata
|
|
|
|
|
|
|
|
|
|
client = pulsar.Client("pulsar://localhost:6650", listener_name="localhost")
|
|
|
|
|
|
|
|
|
|
prod = client.create_producer(
|
|
|
|
|
topic="persistent://tg/flow/text-document-load:0000",
|
|
|
|
|
schema=JsonSchema(TextDocument),
|
|
|
|
|
chunking_enabled=True,
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-02 21:11:50 +01:00
|
|
|
path = "../trustgraph/docs/README.cats"
|
2025-04-24 18:57:33 +01:00
|
|
|
|
|
|
|
|
with open(path, "r") as f:
|
|
|
|
|
# blob = base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
|
blob = f.read()
|
|
|
|
|
|
|
|
|
|
message = TextDocument(
|
|
|
|
|
metadata = Metadata(
|
|
|
|
|
id = "00001",
|
|
|
|
|
metadata = [],
|
|
|
|
|
user="trustgraph",
|
|
|
|
|
collection="default",
|
|
|
|
|
),
|
|
|
|
|
text=blob
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
prod.send(message)
|
|
|
|
|
|
|
|
|
|
prod.close()
|
|
|
|
|
client.close()
|
|
|
|
|
|