我正在使用标准的异步发布者示例.我注意到发布者将永远在循环中继续发布相同的消息.所以我评论了来自publish_message的schedule_next_message调用来停止该循环.但我真正想要的只是当用户给它一个"message_body"和"Key"时,publissher才能开始发布
基本上是发布者发布用户输入.
我无法找到如何使发布者实时接收用户输入的任何示例或提示.我是raabitmq,pika,python等的新手
这是我正在谈论的代码片段: -
def publish_message(self): """If the class is not stopping, publish a message to RabbitMQ, appending a list of deliveries with the message number that was sent. This list will be used to check for delivery confirmations in the on_delivery_confirmations method. Once the message has been sent, schedule another message to be sent. The main reason I put scheduling in was just so you can get a good idea of how the process is flowing by slowing down and speeding up the delivery intervals by changing the PUBLISH_INTERVAL constant in the class. """ if self._stopping: return message = {"service":"sendgrid", "sender": "nutshi@gmail.com", "receiver": "nutshi@gmail.com", "subject": "test notification", "text":"sample email"} routing_key = "email" properties = pika.BasicProperties(app_id='example-publisher', content_type='application/json', headers=message) self._channel.basic_publish(self.EXCHANGE, routing_key, json.dumps(message, ensure_ascii=False), properties) self._message_number += 1 self._deliveries.append(self._message_number) LOGGER.info('Published message # %i', self._message_number) #self.schedule_next_message() #self.stop() def schedule_next_message(self): """If we are not closing our connection to RabbitMQ, schedule another message to be delivered in PUBLISH_INTERVAL seconds. """ if self._stopping: return LOGGER.info('Scheduling next message for %0.1f seconds', self.PUBLISH_INTERVAL) self._connection.add_timeout(self.PUBLISH_INTERVAL, self.publish_message) def start_publishing(self): """This method will enable delivery confirmations and schedule the first message to be sent to RabbitMQ """ LOGGER.info('Issuing consumer related RPC commands') self.enable_delivery_confirmations() self.schedule_next_message()
该网站不允许我添加解决方案..我能够使用raw_input()解决我的问题
谢谢