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
# controllo che il servizio di acquisizione sia attivo ...
# if not self._winservice.isRunning():
# LOGGER.info('Win Service is not running...')
# print 'Win Service is not running...'
# return
message = self.get_message_from_selected_data();
#print "***************************************"
#print json.dumps(message, ensure_ascii=False)
#print "***************************************"
properties = pika.BasicProperties(app_id='myrabbit_py-publisher',
content_type='application/json')
self._channel.basic_publish(self.EXCHANGE,
self.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()
评论列表
文章目录