Skip to content

Commit a8a18d4

Browse files
committed
Docs for kafka loader
1 parent 7e0b6d3 commit a8a18d4

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Kafka Streaming Loader - Usage Guide
2+
3+
Stream blockchain data to Kafka topics in real-time.
4+
5+
## Quick Start
6+
7+
```bash
8+
uv run python apps/kafka_streaming_loader.py \
9+
--topic anvil_logs \
10+
--query-file apps/queries/anvil_logs.sql \
11+
--raw-dataset anvil \
12+
--start-block 0
13+
```
14+
15+
## Basic Usage
16+
17+
### Minimal Example
18+
19+
```bash
20+
uv run python apps/kafka_streaming_loader.py \
21+
--topic my_topic \
22+
--query-file my_query.sql \
23+
--raw-dataset eth_firehose
24+
```
25+
26+
### With Common Options
27+
28+
```bash
29+
uv run python apps/kafka_streaming_loader.py \
30+
--kafka-brokers localhost:9092 \
31+
--topic erc20_transfers \
32+
--query-file apps/queries/erc20_transfers.sql \
33+
--raw-dataset eth_firehose \
34+
--start-block 19000000
35+
```
36+
37+
## Configuration Options
38+
39+
### Required Arguments
40+
41+
| Argument | Description |
42+
|----------|-------------|
43+
| `--topic NAME` | Kafka topic name |
44+
| `--query-file PATH` | Path to SQL query file |
45+
| `--raw-dataset NAME` | Dataset name (e.g., `eth_firehose`, `anvil`) |
46+
47+
### Optional Arguments
48+
49+
| Argument | Default | Description |
50+
|----------|---------|-------------|
51+
| `--kafka-brokers` | `localhost:9092` | Kafka broker addresses |
52+
| `--start-block N` | Latest block | Start streaming from this block |
53+
| `--network NAME` | `anvil` | Network identifier |
54+
| `--label-csv PATH` | - | CSV file for data enrichment |
55+
| `--amp-server URL` | `grpc://127.0.0.1:1602` | AMP server URL |
56+
57+
## Message Format
58+
59+
### Data Messages
60+
61+
Each row is sent as JSON with `_type: 'data'`:
62+
63+
```json
64+
{
65+
"_type": "data",
66+
"block_num": 19000000,
67+
"tx_hash": "0x123...",
68+
"address": "0xabc...",
69+
"data": "0x..."
70+
}
71+
```
72+
73+
### Reorg Messages
74+
75+
On blockchain reorganizations, reorg events are sent:
76+
77+
```json
78+
{
79+
"_type": "reorg",
80+
"network": "ethereum",
81+
"start_block": 19000100,
82+
"end_block": 19000110
83+
}
84+
```
85+
86+
Consumers should invalidate data in the specified block range.
87+
88+
## Examples
89+
90+
### Stream Anvil Logs
91+
92+
```bash
93+
uv run python apps/kafka_streaming_loader.py \
94+
--topic anvil_logs \
95+
--query-file apps/queries/anvil_logs.sql \
96+
--raw-dataset anvil \
97+
--start-block 0
98+
```
99+
100+
### Stream ERC20 Transfers
101+
102+
```bash
103+
uv run python apps/kafka_streaming_loader.py \
104+
--topic erc20_transfers \
105+
--query-file apps/queries/erc20_transfers.sql \
106+
--raw-dataset eth_firehose \
107+
--start-block 19000000 \
108+
--label-csv data/eth_mainnet_token_metadata.csv
109+
```
110+
111+
### Stream from Latest Blocks
112+
113+
```bash
114+
uv run python apps/kafka_streaming_loader.py \
115+
--topic eth_live_logs \
116+
--query-file apps/queries/all_logs.sql \
117+
--raw-dataset eth_firehose
118+
```
119+
120+
## Consuming Messages
121+
122+
Use the consumer script to view messages:
123+
124+
```bash
125+
# Basic usage
126+
uv run python apps/kafka_consumer.py anvil_logs
127+
128+
# Custom broker
129+
uv run python apps/kafka_consumer.py anvil_logs localhost:9092
130+
131+
# Custom consumer group
132+
uv run python apps/kafka_consumer.py anvil_logs localhost:9092 my-group
133+
```
134+
135+
## Docker Usage
136+
137+
```bash
138+
# Build image
139+
docker build -f Dockerfile.kafka -t amp-kafka-loader .
140+
141+
# Run loader
142+
docker run --rm \
143+
--network host \
144+
amp-kafka-loader \
145+
--kafka-brokers localhost:9092 \
146+
--topic my_topic \
147+
--query-file apps/queries/my_query.sql \
148+
--raw-dataset anvil \
149+
--start-block 0
150+
```
151+
152+
## Getting Help
153+
154+
```bash
155+
# View all options
156+
uv run python apps/kafka_streaming_loader.py --help
157+
158+
# View this guide
159+
cat apps/kafka_streaming_loader_guide.md
160+
```

0 commit comments

Comments
 (0)