1+ import asyncio
2+ import json
3+ from datetime import datetime
4+
5+ import aio_pika
6+
7+
8+ async def send_test_log ():
9+ """Send a test log to RabbitMQ."""
10+ # Update with your credentials
11+ connection = await aio_pika .connect_robust (
12+ "amqp://guest:guest@localhost:5672/"
13+ )
14+
15+ async with connection :
16+ channel = await connection .channel ()
17+
18+ # Declare the queue (must match your config)
19+ queue = await channel .declare_queue (
20+ "log_analysis_queue" , # Your queue name
21+ durable = True
22+ )
23+
24+ # Create test log matching your expected format
25+ test_message = {
26+ "data" : {
27+ "type" : "application" ,
28+ "receiver" : "log_analysis_service" ,
29+ "service_name" : "test_service" ,
30+ "log_level" : "INFO" ,
31+ "message" : "This is a test log message" ,
32+ "timestamp" : datetime .now ().isoformat (),
33+ "metadata" : {
34+ "test" : True ,
35+ "source" : "test_script"
36+ }
37+ },
38+ "queue_name" : "log_analysis_queue"
39+ }
40+
41+ # Send message
42+ await channel .default_exchange .publish (
43+ aio_pika .Message (
44+ body = json .dumps (test_message ).encode (),
45+ delivery_mode = aio_pika .DeliveryMode .PERSISTENT ,
46+ content_type = "application/json" ,
47+ ),
48+ routing_key = "log_analysis_queue"
49+ )
50+
51+ print (f"✅ Test log sent successfully!" )
52+ print (f" Service: { test_message ['data' ]['service_name' ]} " )
53+ print (f" Level: { test_message ['data' ]['log_level' ]} " )
54+ print (f" Message: { test_message ['data' ]['message' ]} " )
55+
56+
57+ if __name__ == "__main__" :
58+ asyncio .run (send_test_log ())
0 commit comments