1- from typing import Any , Callable , Union
1+ from typing import Any , Callable , Dict , Union
22
33from servc .svc import ComponentType , Middleware
4+ from servc .svc .config import Config
45from servc .svc .io .input import EventPayload , InputPayload , InputType
56from servc .svc .io .output import StatusCode
67
1011
1112
1213class BusComponent (Middleware ):
14+ name : str = "bus"
15+
1316 _type : ComponentType = ComponentType .BUS
1417
1518 _url : str
1619
17- _routeMap : dict
20+ _routeMap : Dict [ str , str ]
1821
1922 _prefix : str
2023
21- def __init__ (self , url : str , routeMap : dict , prefix : str ):
22- super ().__init__ ()
24+ _instanceId : str
25+
26+ _route : str
27+
28+ def __init__ (self , config : Config ):
29+ super ().__init__ (config )
30+
31+ self ._url = str (config .get ("url" ))
32+ self ._prefix = str (config .get ("prefix" ))
33+ self ._instanceId = str (config .get ("instanceid" ))
34+ self ._route = str (config .get ("route" ))
35+
36+ routemap = config .get ("routemap" )
37+ if routemap is None or not isinstance (routemap , dict ):
38+ routemap = {}
39+ self ._routeMap = routemap
40+
41+ @property
42+ def instanceId (self ) -> str :
43+ return self ._instanceId
2344
24- self . _url = url
25- self . _routeMap = routeMap
26- self ._prefix = prefix
45+ @ property
46+ def route ( self ) -> str :
47+ return self ._route
2748
2849 def getRoute (self , route : str ) -> str :
2950 if route in self ._routeMap :
@@ -33,19 +54,19 @@ def getRoute(self, route: str) -> str:
3354 def publishMessage (self , route : str , message : InputPayload | EventPayload ) -> bool :
3455 return True
3556
36- def emitEvent (self , event : str , instanceId : str , details : Any ) -> bool :
57+ def emitEvent (self , event : str , details : Any ) -> bool :
3758 return self .publishMessage (
3859 self .getRoute (event ),
3960 {
4061 "type" : InputType .EVENT .value ,
4162 "route" : self .getRoute (event ),
4263 "event" : event ,
4364 "details" : details ,
44- "instanceId" : instanceId ,
65+ "instanceId" : self . _instanceId ,
4566 },
4667 )
4768
48- def create_queue (self , queue : str , bindEventExchange : bool = True ) -> bool :
69+ def create_queue (self , queue : str , bindEventExchange : bool ) -> bool :
4970 return False
5071
5172 def delete_queue (self , queue : str ) -> bool :
@@ -59,6 +80,6 @@ def subscribe(
5980 route : str ,
6081 inputProcessor : InputProcessor ,
6182 onConsuming : OnConsuming | None ,
62- bindEventExchange : bool = True ,
83+ bindEventExchange : bool ,
6384 ) -> bool :
6485 return True
0 commit comments