6
6
)
7
7
import pika
8
8
import ssl
9
- from .models import Enqueue
9
+ from .models import Enqueue , Fanout
10
10
from .logger import Logger , LOG_LEVEL
11
11
12
12
@@ -39,6 +39,11 @@ async def list_tools() -> list[Tool]:
39
39
name = "enqueue" ,
40
40
description = """Enqueue a message to a queue hosted on RabbitMQ""" ,
41
41
inputSchema = Enqueue .model_json_schema (),
42
+ ),
43
+ Tool (
44
+ name = "fanout" ,
45
+ description = """Publish a message to an exchange with fanout type""" ,
46
+ inputSchema = Fanout .model_json_schema (),
42
47
)
43
48
]
44
49
@@ -51,7 +56,6 @@ async def call_tool(
51
56
logger .debug ("Executing enqueue tool" )
52
57
message = arguments ["message" ]
53
58
queue = arguments ["queue" ]
54
- # Send to RabbitMQ host
55
59
try :
56
60
connection = pika .BlockingConnection (parameters )
57
61
channel = connection .channel ()
@@ -61,6 +65,19 @@ async def call_tool(
61
65
except Exception as e :
62
66
logger .error (f"{ e } " )
63
67
return [TextContent (type = "text" , text = str ("failed" ))]
68
+ elif name == "fanout" :
69
+ logger .debug ("Executing fanout tool" )
70
+ exchange = arguments ["exchange" ]
71
+ message = arguments ["message" ]
72
+ try :
73
+ connection = pika .BlockingConnection (parameters )
74
+ channel = connection .channel ()
75
+ channel .exchange_declare (exchange = exchange , exchange_type = "fanout" )
76
+ channel .basic_publish (exchange = exchange , routing_key = "" , body = message )
77
+ return [TextContent (type = "text" , text = str ("suceeded" ))]
78
+ except Exception as e :
79
+ logger .error (f"{ e } " )
80
+ return [TextContent (type = "text" , text = str ("failed" ))]
64
81
raise ValueError (f"Tool not found: { name } " )
65
82
66
83
options = server .create_initialization_options ()
0 commit comments