On 22/05/15 11:53, Domingo Yeray Rodríguez Martín wrote:
Is there any reason why one method is static and the other a class method,
and do you think it could be useful to make the second a class method?
you are right that both should be class methods, it makes much more
sense for it to be the case.
However, that alone won’t suffice.
The thing is, when a class representing a service is deployed, that
Python class object doesn’t really have access to anything useful as
regards its Zato environment, i.e. it cannot invoke other services or
publish config messages to servers in a cluster.
It is only in run-time that an instance of a given Python class is
assigned attributes such as self.broker_client, self.request and so on.
Hence the signatures of both before_add_to_store and after_add_to_store
should be rather changed to something like:
def after_add_to_store(cls, server, logger):
Now in your case the new ‘server’ attribute will let the hook access the
underlying broker client so you will be able to publish an internal
config message to the effect that for this new service a new channel
should be created.
You’d need to take timing into account because the new service may be
unavailable yet on certain servers at the time you are already
attempting to create a channel for it but that’s the general idea.
But it cannot be implemented in 2.0.x because it would be a user-visible
change and a modification of the documented API.
However, this is Python so everything is possible. Please have a look at
We’re obtaining a list of instances of the ParallelServer class. This
is the class that is known as self.server to services. There will be
exactly such one instance.
The instance has a .broker_client attribute. This is the same
broker_client that a service’s self.broker_client points to.
In this usage example we’re just invoking zato.helpers.input-logger to
log ‘Hello from after_add_to_store’ received on input.
In your usage scenario, you need to construct correct input for
zato.http-soap.create and invoke it accordingly.
Note that the hook will be invoked by each gunicorn worker so you may
need to add some locks around it. You’d need to try it out yourself.
This will let you achieve the goal without waiting for a new major release.