Automate business processes with Services, Events and Subscriptions.
This project will introduce Services, Events, and Subscriptions inside of the ThingWorx platform.
Following the steps in this guide, you will be able to expand your data model using Services, Events, and Subscriptions.
We will teach you how to make a more robust and enjoyable experience for users simply by using the resources inside of the ThingWorx Composer.
You'll learn how to
Create Events, Services and Subscriptions in Composer
Utilize the ThingWorx Edge SDK platforms with Services, Subscriptions, and Events
NOTE: The estimated time to complete this guide is 60 minutes
Step 1: Completed Example
This guide references the attached EventsServicesSubscription.zip. The sample application is based on a company needing to make deliveries. The rules engine will handle much of the work outside of the transportation workflow.
Unzip and utilize this file to see a finished example and return to it as a reference if you become stuck during this guide and need some extra help or clarification.
Keep in mind, this download uses the exact names for entities used in this tutorial. If you would like to import this example and also create entities on your own, change the names of the entities you create.
Step 2: Functionality
You can combine Services, Subscriptions, and Events to automate business processes or trigger notifications. See the definitions and examples before to gain a better understanding as to the role each plays.
Methods and functions to be used within a ThingWorx application. There are Services provided by the system, but custom services need to be made to create the application's functional requirements. All services in the ThingWorx Composer can be accessed by a user with the appropriate permissions. Remote services can be created with the use of the ThingWorx SDKs.
An Event represent a change in state of a property or changes in a running application. Changes can be handled in different ways based on the method used to fire or queue them. They are a great resource for property value changes and alerts.
The implementation for a subscription is the same as that of a service. Subscriptions are activated when the Event they are listened for is triggered.
Step 3: Create Events
Events are used to mark situations that can occur within an application. They can be used for scenarios ranging from a dangerous situation that is imminent and needs to be checked by personnel to just a system notification. Each Event is based on a DataShape that will hold the necessary information about the Event.
For example, it wouldn’t be enough to just know that a rain Event has occurred. It might be helpful to also know the location, the time the rain started and expectations of the amount of rain to fall.
Follow the steps below to create an Event for the TruckThingTemplate Entity.
Open the TruckThingTemplate Entity and click the Events tab.
Enter an Event name, such as PackageDelivered.
For the DataShape, in the Search Data Shape field, filter and select PackageDataShape.
Step 4: Services Interface
To create Services within ThingWorx, go to the Services tab of the Entity that will house the Service. Our PTCDeliversBusinessLogic Thing will contain several Services for us.
Within the Services tab under the Entity Information section of a Thing, you will see built in functionality for all the ThingTemplates and ThingShapes the Thing inherits from. You will also see the section that allows you to create new Services.
Service Info Tab
This tab is for the general information of the Service. This is where you will add the Service name, description, category, whether the service is asynchronous, and whether the Service can be overridden.
This tab is for the parameters for the Service. For input parameters, a parameter can be required and default values are allowed.
This tab is for the return type of the Service. The resulting output of the Service can stretch from being nothing to user defined Entities.
A listing of all Properties, Events, and Services belonging to custom and provided Entities in ThingWorx. As with the Snippets section, clicking the blue and white arrow will insert the reusable code to wherever the cursor is located. After the code is inserted, update the code to your liking. This is often a great resource for buildiung up payload for Service calls.