Event bus
The event bus provides an alternative way to manage activities. Rather than using triggers to chain activities together, the event bus uses a "publisher and consumer" model:
- Each time a
Publish eventactivity is performed, thePublish eventpublishes data to the bus (using an activity form). Consume eventsare configured to listen for events with a particular key.- When data from a
Publish eventwith a relevant key is published to the bus, this triggers theConsume eventand adds a newConsume eventtask to a queue so that it can be executed.
With an event bus, the publish (or "parent") and consume (or "child") activities are loosely coupled. This can be useful when you want to trigger activities belonging to different casetypes (including some which do not have a relationship to the original case), or when you want to trigger activities on a different Grexx Platform applications.
For example, when a product in an e-commerce platform is marked "out of stock", you might want to exclude it from the list of recommended or related items. You might use a Publish event to record when an item is out of stock and set the key according to the product category. You could then configure different Consume events to listen for different keys and update recommendation and related lists accordingly. You could use a similar approach to apply updates to a mailing list application when customer details are modified.
You can also use an event bus to trigger the same child activity from multiple different parent activities. For example, you might create a Consume event activity to update a person's credit score, and configure that activity to listen for changes to data across multiple casetypes and applications. By setting the same key format on each Publish event, you can configure the Consume event to listen for updates from multiple sources and recalculate the credit score each time.
To use the event bus in your Grexx Platform application, you will need to configure at least one Publish event and at lease one Consume event. You will also need to create a task queue for the Consume event tasks to be added to. Once you have configured an event bus, you can use Developer Tools to monitor the activities and debug any issues.
Publish events
A Publish event is an activity with a form. When the form is submitted, the task data is published to the event bus together with the Publish event key. In turn, this can trigger any number of Consume events (or even none at all).
Before creating a Publish event, create an activity form. The form is used to publish data to the event bus, thereby passing data from the Publish event to the Consume event(s). You can either create a casetype form or a platform form. A platform form is useful if any of the Consume events belongs to a different casetype. Alternatively, you can use casetype forms and specify an external reference for each form field so that the Task out values from the Publish event can be mapped automatically to the Task in of each Consume event.
To create a Publish event:
- Select the relevant casetype and add a Publish event activity.
- In the Publish to topic field, define the activity key. This is used to match a particular published event to one or more consume events.
You can use an inline template to make the key dynamic. For example, you might use thecasemetatemplate function to include the case ID, or thetaskmetatemplate function to include the ID of the parent case or the date the activity was triggered. - From the Form picklist, select the activity form you have created.
- Click Submit. The Publish event activity is created and the activity designer is displayed.
- Add a trigger to initiate the
Publish eventactivity from another activity and/or grant rights to perform the activity as required. You can also add mappings to theOn startstage to populate the activity form fields.
Consume events
A Consume event is triggered when data from a Publish event with a matching key is published to the event bus. Once triggered the Consume event task is added to a queue so that it can be performed automatically.
Before creating a Consume event, navigate to Platform > Queues and create a task queue. You can use the same queue for multiple Consume event activities. For more information about creating task queues, see Create a queue of tasks. (Note that you do not need to create a Queued task to populate the queue.)
To create a Consume event:
- Select the relevant casetype, add an Event activity, and from the Event type picklist, select Consume event.
- In the Consume from topic field, enter the key or key pattern that you want to use to trigger this
Consume event. For example, to trigger theConsume eventeach time an event with a key in the formatcustomer.update.{caseID}is published, entercustomer.update.*. To trigger the event whenever anything is published to the bus, enter*. - From the Queue picklist, select the task queue that you have created for this purpose.
- From the Form picklist, either select the same form as used for the
Publish eventor a dedicated form for theConsume eventactivity. If using a dedicated form, use the External reference to map each field to the corresponding field on thePublish eventform. This ensures theTask outvalues from thePublish eventare mapped to theTask inof theConsume event. - Click Create activity.
- Add mappings and triggers to the
When donestage of theConsume eventas required. For example, to map values from the activity form to attributes on the case, map fromTask outtoCasedata. To concatenate strings from multiple fields into a single attribute, use the+=operator. For more information, see Operators and conditions.
Note that the key that triggers each Consume event is cached on the associated case. If you make changes to the key in the Consume from topic field, you must recalculate the case for these changes to take effect. You can do this by modifying any attribute value or by using the Recalculate case option in Developer Tools.
Monitor the event bus
Once you have configured your events and applied your changes to one or more of your DTAP environments, you can use Developer Tools to monitor the tasks and debug any issues.
Open your application in the relevant environment and press CTRL + ALT + S (on Windows) or Command + Option + S (on MacOS). The Developer Tools window is displayed.
To view the details of a Publish event, including the values submitted in the form:
- Navigate to the case to which the
Publish eventactivity belongs. Alternatively, from Developer Tools select Platform > All cases, use the search and filter options to identify the case, and then click the case ID. - From Developer Tools select Case > Task history and identify the event.
- Click the view icon to view the task details, including the values entered in the form when the task was submitted.
To view the Consume events that have been configured to listen for publish events, open Developer Tools and select Platform > Event bus. All Consume events and their current key patterns are listed. Use the Search publisher key field to refine the list. To refresh the key for a Consume event, click the associated case ID to view the case details and then click Recalculate case.
To view the Consume event tasks that have been triggered by a Publish event, open Developer Tools and select Queue and then select the relevant task queue. For more information about managing the tasks in a queue, see Create a queue of tasks.