I am testing the pub/sub system included in Zato.
I have a service genesisng.services.availability.Confirm that creates a reservation. The service, hot-deployed and working fine, at the end of a successful execution, publishes a message to a topic named /genesisng/bookings/new:
# Publish a message to ``/genesisng/bookings/new`` topic name. topic_name = '/genesisng/bookings/new' data = 'id:%s' % booking['response'].id priority = self.user_config.genesisng.availability.pubsub_priority msg_id = self.pubsub.publish(topic_name, data=data, priority=priority) self.logger.info('Added message with id %s to topic %s for booking with id %s' % (msg_id, topic_name, booking['response'].id))
The topic name /genesisng/bookings/new was created using the web admin menu option Pub/sub > Topics with default values.
This part is working fine and I can see the published messsages via the web admin option Pub/sub > Topics.
Now I am trying to code a subscriber named genesisng.pubsub.sender.Sender as a Zato service (using Python). This service will consume messages from the topic /genesisng/bookings/new and compose and send an email to the guest via SMTP on the localhost.
Do I need to create an endpoint for the publisher and another endpoint for the subscriber? From the documentation, given that both are Python services executed inside Zato, I understand that it is not necessary (it seems to be using the zato.pubsub.default.internal.endpoint default value).
How do I deploy my subscriber, i.e. how do I tell Zato that service is a subscriber to the pub/sub system and has to be executed as such? I see that the web admin menu option Pub/sub > Subscriptions allows adding subscribers, but only through AMQP, REST and SOAP and require and endpoint. And, given that my subscriber service is made in Python as a Zato service, I understand it should not be necessary to either create an endpoint nor a subscriber (that’s for external subscribers). Moreover, endpoints are of types AMQP, REST, SOAP and WebSockets, which is not my case.
This is my sender so far:
# -*- coding: utf-8 -*- from __future__ import absolute_import, division from __future__ import print_function, unicode_literals from zato.server.service import Service class Sender(Service): def handle(self): self.logger.info('Executing sender subscriber service') topic_name = '/genesisng/bookings/new' sub_key = self.pubsub.subscribe(topic_name, service=self) self.logger.info('Sender service subscribed to topic name %s and received subscription key %s', topic_name, sub_key) # Get available messages messages = self.pubsub.get_messages(topic_name, sub_key) self.logger.info('Messages received from topic name %s are %s', topic_name, messages) # Compose a new reservation email and send it to the guest self.logger.info('Sending email to guest')
I am afraid that I am a bit overwhelmed by all the pub/sub and broker documentation because it aims at a very complex system which I do not require, and most probably the answer is very simple and located somewhere in such documentation (I must have missed it).
Any help will be appreciated. I’ll keep re-reading it meanwhile.