Course 8: Model Events and Agents
In this course you will learn about the relation of Business Events and Agents and how to mdoel them in a Domain Namespace using the Solution Designer.
Exerciseโ
Estimated time: 30 minutes
Supported languages: TypeScript and Java
Precondition: Course Domain Service Development
In this exercise you will learn to design an Event and the Agent within the Orders Project.
Please note that the links to the workbench tools in this tutorial only apply to the IBM Education Environment we provide. If you are using a different environment, e.g. your own installation, you will need to navigate directly to the required tools.
Introductionโ
In this use case, the customer should get notified once the status of the order has been changed. To fullfill the use case we need to design an Event and an Agent.
Open your imported Orders projectโ
The following steps will take your Orders project which you have imported in Course Domain Service Development as a base.
- Open your Workspace in the Solution Designer.
- Find your imported Project and open it by clicking on it.
Create a new Business Eventโ
Whenever the status of the order gets changed, we want to publish an event. For this use case the Event will be called OrderStatusChanged.
Please consider selecting appropriate names for the event and for the schema, so that it's easy for you to map the schema to the corresponding event.
To create the Business Event, please follow the following steps:
-
Open the domain namespace "ord" (Overview of Orders)
-
Navigate to the Tab "Events" click on "Create"
-
Create a new Event and fill in the following data:
- Local Identifier: OrderStatusChanged
- Label: Order Status has been Changed
- Event Topic Binding:
your-acronym
-orders
If your Event Topic Bindng does not exist, you will see a new slide where to create the event topic binding. Just fill the mandatory fields and click on "Create". Then you get back to the previous slide. Click on "Create" to create the new Event.
Create Schema in the registryโ
- Click on Schemas from the left menu.
- Create the Schema registry and input the Identifier, name, and version.
- Click "Next".
- Add the properties needed. In our example, status and CustomerId.
- Click "Create".
Create the Event Payloadโ
An Event Payload is carried by each Business Event. It typically contains information regarding the Event. In our example we would define customerId and status as a Event Payload for the Business Event OrderStatusChanged.
-
Therefore open the Business Event OrderStatusChanged.
-
Click on "Select Schema from Schema Registry".
-
Select the schema you want to use and click "Next".
-
Select the version and checkout the details, it should have the following properties.
- status
- customerId
-
Click "Add".
You have successfully desgined a Business Events and its Payload.
Create an Event Agentโ
Previously we have defined the Business Event OrderStatusChanged. Each time the status of the Order changes, the event will be thrown. In our example we want to receive a notification each time the status of the Order is changed. In order to do that, we need to define an Agent OrderStatusChangedAgent. that is triggered whenever the Event has been published.
To create the Agent, please follow the following steps:
-
Go back to the Domain Namespace "ord" (Overview of Orders)
-
Navigate to the Tab "Agents"
-
Create a new Agent with the following data:
- Type: EventAgent
- TriggerEvent: OrderStatusChanged
- Local Identifier: OrderStatusChangedAgent
One cannot define an input for Agents. The Payload of the trigger Event will be automatically taken as input entity for the Agent.
You have successfully desgined the Event Agent.
Open the Event and discover the assigned Agentโ
Please follow the following steps:
-
Open the Agent Tab then open the agent you just created.
-
In the agent details section, you can see the triggered event.
-
If you clicked on the triggered event, the event details will show up and you will also see the assigned agent under the "Usages" section.
Since the Event is currently being used by an Agent, it cannot be deleted.
Commit and Push changesโ
As a last step, please commit and push the changes by clicking on the responsible icon and provide a suitable commit message.
You have successfully pushed the changes to the git repository.
Related Linksโ
Please find more information about Model Domain services: