@@ -511,6 +511,7 @@ def __init__(self, logger, pipeline_args: dict = None, load_balance=False, is_mu
511
511
if pika is None :
512
512
raise ValueError ("To use AMQP you must install the 'pika' library." )
513
513
self .properties = pika .BasicProperties (delivery_mode = 2 ) # message persistence
514
+ self .heartbeat = 10
514
515
515
516
def load_configurations (self , queues_type ):
516
517
self .host = self .pipeline_args .get (f"{ queues_type } _pipeline_host" , "10.0.0.1" )
@@ -533,9 +534,9 @@ def load_configurations(self, queues_type):
533
534
self .kwargs ['ssl_options' ] = pika .SSLOptions (context = ssl .create_default_context (ssl .Purpose .SERVER_AUTH ))
534
535
pika_version = tuple (int (x ) for x in pika .__version__ .split ('.' ))
535
536
if pika_version < (0 , 11 ):
536
- self .kwargs ['heartbeat_interval' ] = 10
537
+ self .kwargs ['heartbeat_interval' ] = self . heartbeat
537
538
else :
538
- self .kwargs ['heartbeat' ] = 10
539
+ self .kwargs ['heartbeat' ] = self . heartbeat
539
540
if pika_version < (1 , ):
540
541
# https://groups.google.com/forum/#!topic/pika-python/gz7lZtPRq4Q
541
542
self .publish_raises_nack = False
@@ -607,7 +608,10 @@ def _send(self, destination_queue, message, reconnect=True):
607
608
mandatory = True ,
608
609
)
609
610
except Exception as exc : # UnroutableError, NackError in 1.0.0
610
- if reconnect and isinstance (exc , pika .exceptions .ConnectionClosed ):
611
+ if reconnect and (
612
+ isinstance (exc , pika .exceptions .ConnectionClosed ) or
613
+ isinstance (exc , pika .exceptions .StreamLostError )
614
+ ):
611
615
self .logger .debug ('Error sending the message. '
612
616
'Will re-connect and re-send.' ,
613
617
exc_info = True )
@@ -645,9 +649,13 @@ def _receive(self) -> bytes:
645
649
if self .source_queue is None :
646
650
raise exceptions .ConfigurationError ('pipeline' , 'No source queue given.' )
647
651
try :
648
- method , header , body = next (self .channel .consume (self .source_queue ))
649
- if method :
650
- self .delivery_tag = method .delivery_tag
652
+ method , body = None , None
653
+ while not (method or body ):
654
+ method , _ , body = next (
655
+ self .channel .consume (self .source_queue , inactivity_timeout = self .heartbeat / 2 )
656
+ )
657
+ if method :
658
+ self .delivery_tag = method .delivery_tag
651
659
except Exception as exc :
652
660
raise exceptions .PipelineError (exc )
653
661
else :
0 commit comments