Configuring Event Notifications for Service Instance Changes
Overview
This article explains how to configure services to receive notifications when service instances are created, updated, or deleted. Event notifications allow services to automatically respond to changes occurring in other services, enabling automated dependency management and business rule enforcement.
Background
Event notifications provide a mechanism for services to react dynamically to changes in other services within Activate.
This functionality is similar to the existing SupportsUpdateUser process, where services register to receive notifications whenever a user's details are updated. When a service supports the Update User process, it can perform actions automatically whenever user information changes.
Using event notifications, services can:
- Maintain up-to-date configurations.
- Automatically manage dependencies between services.
- Trigger actions when service access changes.
- Reduce manual administration.
- Improve system responsiveness and integration between services.
Supported Events
The following service instance events can generate notifications:
Event | Description |
|---|---|
Create | Triggered when a service instance is created. |
Update | Triggered when a service instance is updated. |
Delete | Triggered when a service instance is deleted. |
Use Case Example
Consider an organisation that provides a USB Drive Access service and an Oracle Access service.
Users are permitted to have USB Drive Access only if they do not have Oracle Access.
Scenario
- A user currently has USB Drive Access.
- The user later requests Oracle Access.
- Oracle Access is approved and provisioned.
- USB Drive Access must be automatically revoked.
Solution
The USB Drive Access service registers for Create event notifications from the Oracle Access service.
When Oracle Access is granted:
- A service instance is created for Oracle Access.
- The Oracle service generates a Create notification.
- The USB Drive Access service receives the notification.
- The USB Drive Access service checks whether the user has USB access.
- If USB access exists, the service automatically revokes it.
This ensures service dependencies are enforced without manual intervention.
Initial Configuration
Install the Services Event Setup Package
Install the Services Event Setup package.
The package adds the following components:
Template Parameters
Added to the root of Services:
Event Script
A new EventScript is added to:
Update the Services Root Script
Update the main Services script located at:
Add the following lines immediately after the CustomScript call within the corresponding functions.
Create
Update
Delete
Service Configuration
Configure the Receiving Service
On the service that will receive event notifications, add the following stub methods to the service's Custom Script.
These methods are invoked when the service receives a notification.
Add the required logic inside these methods to perform the desired actions when notifications are received.
Configure the Publishing Service
On the service that will generate notifications, configure the appropriate event parameter and specify the path of the service that should be notified.
Available Parameters
Example
To notify the USB Drive Access service whenever Oracle Access is granted:
- Open the Oracle service configuration.
- Set the parameter:
- Enter the path to the USB Drive Access service.
When an Oracle service instance is created, the USB Drive Access service will receive an OnCreate() notification.
Supporting Multiple Subscribers
A single service can notify multiple services.
For example:
may contain multiple service paths, allowing several services to receive notifications whenever an Oracle service instance is created.
This enables complex dependency management scenarios where multiple services need to react to the same event.
Summary
Event notifications provide a flexible mechanism for automating service dependency management within Activate. By registering services for Create, Update, or Delete events, organisations can automatically enforce business rules, maintain service compliance, and reduce manual administration.
Package
<Innovation.Activate.Package>
<Link Path="//Services">
<parameter Name="Events.Instance.OnCreate" Description="This Service will be notified of Create Events from the registered service." Type="Reference" Flags="Template" Version="1" />
<parameter Name="Events.Instance.OnDelete" Description="This Service will be notified of Delete Events from the registered service." Type="Reference" Flags="Template" Version="1" />
<parameter Name="Events.Instance.OnUpdate" Description="This Service will be notified of Update Events from the registered service." Type="Reference" Flags="Template" Version="1" />
</Link>
<Link Path="//Resources/Services">
<parameter Name="EventScript" Description="" Type="Script" Flags="None" Version="1"><![CDATA[using System;
using Innovation.Activate;
class Script : ScriptBase
{
public const String eventBaseName = "Events.Instance.";
public void main()
{
ServiceInstance srv = ServiceInstance.GetServiceInstance(16246);
OnNotifyDelete(srv);
}
public void OnNotifyCreate(ServiceInstance srv)
{
OnNotify(srv, "OnCreate");
}
public void OnNotifyUpdate(ServiceInstance srv)
{
OnNotify(srv, "OnUpdate");
}
public void OnNotifyDelete(ServiceInstance srv)
{
OnNotify(srv, "OnDelete");
}
public void OnNotify(ServiceInstance srv, String eventName)
{
ParameterCollection notificationServices = srv.Service.GetParameters(eventBaseName + eventName + "*");
if (notificationServices.Count == 0) return;
foreach (Parameter p in notificationServices)
{
Service s = p.EvaluateToObject(null, null) as Service;
if (s == null)
continue;
ServiceInstance srv2 = srv.User.Services.Find(s, false); // Find the service if the user has it
if (srv2 != null)
{
Trace.WriteLine(srv2.Name);
Job.WorkFlow.CallOptionalScript("=" + srv2.Service.InternalPath + "/CustomScript", eventName, srv2);
}
}
}
}
]]></parameter>
</Link>
</Innovation.Activate.Package>