Event Bus
Last updated
Last updated
As of Amphora version 6.6.0
the option of using has been introduced. This event bus is intended to make it easier to a destructure a Clay instance and supporting platform packages (i.e. Amphora Search). By default the Bus module is not instantiated. Only by setting the will the Bus module be active.
The Event Bus is also intended to replace the plugin system in the next major version of Amphora (v7). On top of replacing the plugin system, the event bus will see some small changes to the payload of certain events as the plugin system is rearchitected. The end goal is to expose specific hooks in the Amphora lifecycle to the Bus as quickly as possible.
The following topics are published to the bus by Amphora:
clay:publishLayout
clay:publishPage
clay:createPage
clay:unschedulePage
clay:schedulePage
clay:unpublishPage
clay:save
clay:delete
The Bus module has two configurations options which are both controlled by environment variables.
As mentioned, the Bus module is turned off by default. Only by setting the CLAY_BUS_HOST
env var to a valid Redis url (redis://<HOST>:<PORT>
) will the module be instantiated and events will be published to the instance.
By default, all topics published to the Bus are namespaced using clay
, i.e. clay:<ACTION>
. This namespace can be configured by the env var CLAY_BUS_NAMESPACE
. For example, setting CLAY_BUS_NAMESPACE
to a value of mysite
will publish all events as mysite:<ACTION>
.
Provided you have setup Amphora to pub to a Redis instance, the following code will subscribe to all events from Clay using the NPM module.