2013-12-18 5 views
6

में खपत को रोकें और फिर से शुरू करें कैसे मैं उपभोग करने के लिए संदेशों और मूल_cancel प्राप्त करने के लिए basic_consume() का उपयोग कर रहा हूं, लेकिन एक समस्या है।खरगोश, पिका पायथन

यहाँ pika.channel

def basic_consume(self, consumer_callback, queue='', no_ack=False, 
         exclusive=False, consumer_tag=None): 
     """Sends the AMQP command Basic.Consume to the broker and binds messages 
     for the consumer_tag to the consumer callback. If you do not pass in 
     a consumer_tag, one will be automatically generated for you. Returns 
     the consumer tag. 

     For more information on basic_consume, see: 
     http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume 

     :param method consumer_callback: The method to callback when consuming 
     :param queue: The queue to consume from 
     :type queue: str or unicode 
     :param bool no_ack: Tell the broker to not expect a response 
     :param bool exclusive: Don't allow other consumers on the queue 
     :param consumer_tag: Specify your own consumer tag 
     :type consumer_tag: str or unicode 
     :rtype: str 

     """ 
     self._validate_channel_and_callback(consumer_callback) 

     # If a consumer tag was not passed, create one 
     consumer_tag = consumer_tag or 'ctag%i.%s' % (self.channel_number, 
                 uuid.uuid4().get_hex()) 

     if consumer_tag in self._consumers or consumer_tag in self._cancelled: 
      raise exceptions.DuplicateConsumerTag(consumer_tag) 

     self._consumers[consumer_tag] = consumer_callback 
     self._pending[consumer_tag] = list() 
     self._rpc(spec.Basic.Consume(queue=queue, 
            consumer_tag=consumer_tag, 
            no_ack=no_ack, 
            exclusive=exclusive), 
          self._on_eventok, 
          [(spec.Basic.ConsumeOk, 
          {'consumer_tag': consumer_tag})]) 

     return consumer_tag 

def basic_cancel(self, callback=None, consumer_tag='', nowait=False): 
     """This method cancels a consumer. This does not affect already 
     delivered messages, but it does mean the server will not send any more 
     messages for that consumer. The client may receive an arbitrary number 
     of messages in between sending the cancel method and receiving the 
     cancel-ok reply. It may also be sent from the server to the client in 
     the event of the consumer being unexpectedly cancelled (i.e. cancelled 
     for any reason other than the server receiving the corresponding 
     basic.cancel from the client). This allows clients to be notified of 
     the loss of consumers due to events such as queue deletion. 

     :param method callback: Method to call for a Basic.CancelOk response 
     :param str consumer_tag: Identifier for the consumer 
     :param bool nowait: Do not expect a Basic.CancelOk response 
     :raises: ValueError 

     """ 
     self._validate_channel_and_callback(callback) 
     if consumer_tag not in self.consumer_tags: 
      return 
     if callback: 
      if nowait is True: 
       raise ValueError('Can not pass a callback if nowait is True') 
      self.callbacks.add(self.channel_number, 
           spec.Basic.CancelOk, 
           callback) 
     self._cancelled.append(consumer_tag) 
     self._rpc(spec.Basic.Cancel(consumer_tag=consumer_tag, 
            nowait=nowait), 
        self._on_cancelok, 
        [(spec.Basic.CancelOk, 
        {'consumer_tag': consumer_tag})] if nowait is False else []) 

आप हर बार जब मैं खपत consumer_tag रद्द कर रहा हूँ देख सकते हैं की कोड _canceled सूची में जोड़ा जाता है। और यदि मैं इस टैग का उपयोग मूल_consume में फिर से करता हूं तो डुप्लिकेटकंस्यूमर अपवाद उठाया जाएगा। ठीक है, मैं हर बार एक नया उपभोक्ता_टैग का उपयोग कर सकता हूं, लेकिन वास्तव में मैं नहीं हूं। क्योंकि जल्द या बाद में जेनरेट किया गया टैग बिल्कुल पिछले कुछ लोगों से मेल खाता होगा।

मुझे पिका में खपत को खपत और फिर से शुरू करना चाहिए?

उत्तर

1

क्या कोई कारण है कि आप अपना खुद का consumer_tags परिभाषित करते हैं? आप एक खाली स्ट्रिंग पास कर सकते हैं और RabbitMQ को आपके लिए उपभोक्ता टैग जेनरेट करने दें। basic.consume का उत्तर, जो basic.consume-ok है consumer_tag उत्पन्न करेगा, ताकि आप इसे बाद में उपभोग करने के लिए उपयोग कर सकें।

देखें: http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume-ok

+0

पिका मॉड्यूल के संलग्न कोड से, यह स्पष्ट है कि यहां तक ​​कि क्लाइंट एप्लिकेशन उपभोक्ता टैग निर्दिष्ट नहीं करता है, तो पिका मॉड्यूल एक उत्पन्न करेगा और इसे उपभोग अनुरोध में शामिल करेगा। – mike

1

कि पिका तरह लग रहा है और अधिक से अधिक यह होना चाहिए कर रही है - यह अगर एक आपूर्ति नहीं की गई एक उपभोक्ता टैग बनाने की आवश्यकता नहीं है (सर्वर होगा) और यह भी की जरूरत नहीं है डुप्लीकेट उपभोक्ता टैग के लिए देखें (उसी टैग के साथ फिर से शुरू करना सर्वर द्वारा समर्थित है)।

तो मुझे यकीन नहीं है कि यह पिका के साथ कैसे करें - मुझे लगता है कि एक बग फ़ाइल करें।

संबंधित मुद्दे