Configuration

nti.webhooks uses zope.configuration.xmlconfig and ZCML files for basic configuration.

Loading the default configure.zcml for this package establishes some defaults, such as the default global webhook delivery manager.

>>> from zope.configuration import xmlconfig
>>> conf_context = xmlconfig.string("""
... <configure
...     xmlns="http://namespaces.zope.org/zope"
...     xmlns:webhooks="http://nextthought.com/ntp/webhooks"
...     >
...   <include package="nti.webhooks" />
... </configure>
... """)

Important

By itself, that is not enough for this package to be functional.

The subscriber nti.webhooks.subscribers.dispatch_webhook_event() must be registered as well, for some combination of data object and (descendent of) zope.interface.interfaces.IObjectEvent.

Note

Descending from IObjectEvent is not actually required, so long as the event provides the object attribute, and so long as double-dispatch from a single event to the double (object, event) subscriber interface happens. This is automatic for IObjectEvent.

Because IObjectEvent and its descendents are extremely common events, that subscriber is not registered by default. Doing so could add unacceptable overhead to common application actions. It is suggested that your application integration should register the subscriber for a subset of “interesting” events and data types.

Your application integration is free to register the subscriber for exactly the events that are desired. Or, to assist with common cases, this package provides two additional ZCML files.

Development and Testing: subscribers_promiscuous.zcml

This file registers the dispatcher for all object events for all objects: (*, IObjectEvent*).

This may have performance consequences, so its use in production systems is discouraged (unless the system is small). However, it is extremely useful during development and (unit) testing and while deciding which objects and events make useful webhooks.

Many of the tests and examples in the documentation for this package use this file.

For example:

>>> conf_context = xmlconfig.string("""
... <configure
...     xmlns="http://namespaces.zope.org/zope"
...     xmlns:webhooks="http://nextthought.com/ntp/webhooks"
...     >
...   <include package="nti.webhooks" />
...   <include package="nti.webhooks" file="subscribers_promiscuous.zcml" />
... </configure>
... """)