Configuring Event Notifications for Service Instance Changes
19 min
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 events instance oncreate events instance onupdate events instance ondelete event script a new eventscript is added to //resources/services update the services root script update the main services script located at //services/script add the following lines immediately after the customscript call within the corresponding functions create job workflow\ callscript( "=//resources/services/eventscript", "onnotifycreate", srv ); update job workflow\ callscript( "=//resources/services/eventscript", "onnotifyupdate", srv ); delete job workflow\ callscript( "=//resources/services/eventscript", "onnotifydelete", srv ); 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 \#region events public void oncreate(serviceinstance srv) { } public void onupdate(serviceinstance srv) { } public void ondelete(serviceinstance srv) { } \#endregion 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 events instance oncreate events instance onupdate events instance ondelete example to notify the usb drive access service whenever oracle access is granted open the oracle service configuration set the parameter events instance oncreate 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 events instance oncreate 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>