One of many great things about Zato is the fact how easy it is to plug into it new data sources and input methods triggering one's SOA/API services.

For instance, Zato 2.0 does not have a web-admin GUI for file notifications but it is still possible to listen for new or updated files in directories of choice and invoke services each time a new event arrives, e.g. when a new file is dropped into a directory, effectively creating a new channel type in addition to what Zato comes with out of the box.

This is exactly what the script below does - it uses watchmedo, part of the watchdog package, to listen for events in a given directory. Each time anything of interest happens in that directory (here - in /tmp/data) a Zato service defined below is invoked with a path to that item of interest provided on input.


watchmedo shell-command \
    --patterns="*" \
    --command='curl localhost:11223/file.notifications?path=${watch_src_path}; echo' \

It's entirely up to that service to decide how to handle the data in each file - one can decide to deliver it to any of outgoing connections in Zato using, for instance, AMQP, SMTP, FTP, ElasticSearch, Solr or do anything else that is required in a given integration scenario.


Just to exemplify the idea, in this blog post the data is simply stored in server.log:

# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# Zato
from zato.server.service import Service

class FileNotifications(Service):
    name = 'file.notifications'

    class SimpleIO(object):
        input_required = ('path',)

    def handle(self):

        # Read data in
        data = open(self.request.input.path).read().strip()

        # Since this is just an example, only log the contents of what was read in'Data from %s is `%s`', self.request.input.path, data)

Such a service needs to be mounted on an HTTP channel, as below.


If you have not done it yet, create a directory /tmp/data and start the watchmedo script above before continuing with the next steps.

Now we can create a new file and observe in server.log what happens, how the service reacts to it:


Sure enough, server.log confirms that everything works as expected: