@@ -37,7 +37,7 @@ def __init__(self, amqp_url, node_id=None):
3737
3838 """
3939 self ._connection = None
40- self ._channel : Channel = None
40+ self .channel : Channel = None
4141
4242 self ._deliveries = None
4343 self ._acked = None
@@ -87,7 +87,7 @@ def on_connection_closed(self, connection, reply_code, reply_text):
8787 :param str reply_text: The server provided reply_text if given
8888
8989 """
90- self ._channel = None
90+ self .channel = None
9191 if self ._stopping :
9292 self ._connection .ioloop .stop ()
9393 else :
@@ -101,7 +101,7 @@ def open_channel(self):
101101
102102 def on_channel_open (self , channel ):
103103 LOGGER .info ('Channel opened' )
104- self ._channel : Channel = channel
104+ self .channel : Channel = channel
105105 # self._channel.basic_qos(prefetch_count=1) # TODO: figure out why prefetch must be disabled to make it work
106106 # self._channel.confirm_delivery() # Enabled delivery confirmations
107107 self .add_on_channel_close_callback ()
@@ -115,25 +115,25 @@ def start_heartbeating(self):
115115 'sender' : self .NODE_ID ,
116116 'cpu' : psutil .cpu_percent (interval = None )
117117 }
118- self ._channel .basic_publish (MOLECULER_EXCHANGES ['HEARTBEAT' ], '' ,
119- json .dumps (heartbeat_packet ))
118+ self .channel .basic_publish (MOLECULER_EXCHANGES ['HEARTBEAT' ], '' ,
119+ json .dumps (heartbeat_packet ))
120120 self ._connection .add_timeout (self .HEARTBEAT_INTERVAL , self .start_heartbeating )
121121
122122 def subscribe_to_topics (self ):
123123 if self .is_bindings_ready :
124124 self .add_on_cancel_callback ()
125125 # for queue in self.moleculer_topics.queues.values():
126- self ._channel .basic_consume (self .consumer .discover , self .moleculer_topics .queues ['DISCOVER' ])
127- self ._channel .basic_consume (self .consumer .info , self .moleculer_topics .queues ['INFO' ])
128- self ._channel .basic_consume (self .consumer .ping , self .moleculer_topics .queues ['PING' ])
129- self ._channel .basic_consume (self .consumer .request , self .moleculer_topics .queues ['REQUEST' ])
130- self ._channel .basic_consume (self .consumer .response , self .moleculer_topics .queues ['RESPONSE' ])
131- self ._channel .basic_consume (self .consumer .event , self .moleculer_topics .queues ['EVENT' ])
126+ self .channel .basic_consume (self .consumer .discover , self .moleculer_topics .queues ['DISCOVER' ])
127+ self .channel .basic_consume (self .consumer .info , self .moleculer_topics .queues ['INFO' ])
128+ self .channel .basic_consume (self .consumer .ping , self .moleculer_topics .queues ['PING' ])
129+ self .channel .basic_consume (self .consumer .request , self .moleculer_topics .queues ['REQUEST' ])
130+ self .channel .basic_consume (self .consumer .response , self .moleculer_topics .queues ['RESPONSE' ])
131+ self .channel .basic_consume (self .consumer .event , self .moleculer_topics .queues ['EVENT' ], no_ack = True )
132132
133133 for queue_name in self .moleculer_topics .action_queues :
134- self ._channel .basic_consume (self .consumer .request , queue_name )
134+ self .channel .basic_consume (self .consumer .request , queue_name )
135135 for queue_name in self .moleculer_topics .event_queues :
136- self ._channel .basic_consume (self .consumer .event , queue_name , no_ack = True )
136+ self .channel .basic_consume (self .consumer .event , queue_name , no_ack = True )
137137
138138 self ._connection .add_timeout (0.5 , self .discover_packet )
139139 else :
@@ -181,22 +181,22 @@ def is_bindings_ready(self):
181181 def bind_queues_to_exchanges (self ):
182182 self .expect_bindings_count = len (self .moleculer_topics .bindings )
183183 for queue_name , fanout_name in self .moleculer_topics .bindings .items ():
184- self ._channel .queue_bind (self .on_bindok , queue_name , fanout_name )
184+ self .channel .queue_bind (self .on_bindok , queue_name , fanout_name )
185185
186186 def add_on_channel_close_callback (self ):
187187 """This method tells pika to call the on_channel_closed method if
188188 RabbitMQ unexpectedly closes the channel.
189189
190190 """
191191 LOGGER .info ('Adding channel close callback' )
192- self ._channel .add_on_close_callback (self .on_channel_closed )
192+ self .channel .add_on_close_callback (self .on_channel_closed )
193193
194194 def discover_packet (self ):
195195 req = {
196196 'ver' : '2' ,
197197 'sender' : self .NODE_ID
198198 }
199- self ._channel .basic_publish (MOLECULER_EXCHANGES ['DISCOVER' ], '' , json .dumps (req ))
199+ self .channel .basic_publish (MOLECULER_EXCHANGES ['DISCOVER' ], '' , json .dumps (req ))
200200
201201 def on_channel_closed (self , channel , reply_code , reply_text ):
202202 """Invoked by pika when RabbitMQ unexpectedly closes the channel.
@@ -211,7 +211,7 @@ def on_channel_closed(self, channel, reply_code, reply_text):
211211
212212 """
213213 LOGGER .warning ('Channel was closed: (%s) %s' , reply_code , reply_text )
214- self ._channel = None
214+ self .channel = None
215215 if not self ._stopping :
216216 self ._connection .close ()
217217
@@ -224,9 +224,9 @@ def setup_exchange(self, exchange_name):
224224
225225 """
226226 LOGGER .info ('Declaring exchange %s' , exchange_name )
227- self ._channel .exchange_declare (self .on_exchange_declareok ,
228- exchange_name ,
229- self .EXCHANGE_TYPE , durable = True )
227+ self .channel .exchange_declare (self .on_exchange_declareok ,
228+ exchange_name ,
229+ self .EXCHANGE_TYPE , durable = True )
230230
231231 def on_exchange_declareok (self , unused_frame ):
232232 """Invoked by pika when RabbitMQ has finished the Exchange.Declare RPC
@@ -252,8 +252,8 @@ def setup_queue(self, queue_name, ttl=True, exclusive=False, durable=False):
252252 arguments = {}
253253 if ttl :
254254 arguments ['x-message-ttl' ] = 5000 # eventTimeToLive: https://github.com/ice-services/moleculer/pull/72
255- self ._channel .queue_declare (self .on_queue_declareok , queue_name ,
256- exclusive = exclusive , durable = durable , arguments = arguments )
255+ self .channel .queue_declare (self .on_queue_declareok , queue_name ,
256+ exclusive = exclusive , durable = durable , arguments = arguments )
257257
258258 def on_queue_declareok (self , method_frame ):
259259 """Method invoked by pika when the Queue.Declare RPC call made in
@@ -282,7 +282,7 @@ def add_on_cancel_callback(self):
282282
283283 """
284284 LOGGER .info ('Adding consumer cancellation callback' )
285- self ._channel .add_on_cancel_callback (self .on_consumer_cancelled )
285+ self .channel .add_on_cancel_callback (self .on_consumer_cancelled )
286286
287287 def on_consumer_cancelled (self , method_frame ):
288288 """Invoked by pika when RabbitMQ sends a Basic.Cancel for a consumer
@@ -293,8 +293,8 @@ def on_consumer_cancelled(self, method_frame):
293293 """
294294 LOGGER .info ('Consumer was cancelled remotely, shutting down: %r' ,
295295 method_frame )
296- if self ._channel :
297- self ._channel .close ()
296+ if self .channel :
297+ self .channel .close ()
298298
299299 def run (self ):
300300 """Run the service code by connecting and then starting the IOLoop.
@@ -332,8 +332,8 @@ def stop(self):
332332 'ver' : '2' ,
333333 'sender' : self .NODE_ID
334334 }
335- self ._channel .basic_publish (MOLECULER_EXCHANGES ['DISCONNECT' ], '' ,
336- json .dumps (disconnect_packet ))
335+ self .channel .basic_publish (MOLECULER_EXCHANGES ['DISCONNECT' ], '' ,
336+ json .dumps (disconnect_packet ))
337337 self ._stopping = True
338338 self .close_channel ()
339339 self .close_connection ()
@@ -343,9 +343,9 @@ def close_channel(self):
343343 the Channel.Close RPC command.
344344
345345 """
346- if self ._channel is not None :
346+ if self .channel is not None :
347347 LOGGER .info ('Closing the channel' )
348- self ._channel .close ()
348+ self .channel .close ()
349349
350350 def close_connection (self ):
351351 """This method closes the connection to RabbitMQ."""
0 commit comments