Set up WebSockets in Intrexx
Create topic
Topics are created in the "Applications" module.
Step-by-step guide
To create a topic in an application, please proceed as follows:
-
Open the properties dialog of the application that you would like to create the topic in. You can access the properties via the application node.
-
Switch to the "Topics" tab.
-
Click on the icon.
The fields "GUID of the topic" and "Name of the topic" will appear on the right:
Name
Description
GUID of the topic
The topic GUID is shown in the right area of the dialog. Intrexx assigns the GUID automatically, it cannot be changed. You need the GUID if you want to refer to this topic in a Groovy action or JavaScript.
Name of the topic
Provide the topic with a name here. This name must be unique, it may only be used in Intrexx once. It may only be used in Intrexx once. You can use the topic name if you want to refer to the topic in WebSocket actions.
-
(Optional) Click on the icon again to create additional topics.
You can add any number of topics to an application.
You have now created a topic in an application.
Write JavaScript for WebSockets in the application
Step-by-step guide
To write JavaScript for WebSockets in an application, please proceed as follows:
-
Open the application that you would like to display the WebSocket message in.
(This is also the application that contains the topic that you would like to subscribe to via JavaScript.) -
Open the JavaScript editor (Ctrl + F12).
-
Write the JavaScript code.
a. Write the function for subscribing to the topic and for displaying the message in the portal.
b. (Optional) Write the function for unsubscribing from the topic. -
Define a (JavaScript) event that will
a. Start the subscription (e.g. onload, click)
b. (Optional) end the subscription.
Configure WebSocket action
WebSocket actions are configured in the "Processes" module.
Requirements/preparations
In the normal manner, add a WebSocket action to the corresponding process.
Step-by-step guide
To configure a WebSocket action, please proceed as follows:
-
Open the properties dialog of the WebSocket action.
-
Provide the WebSocket action with a title and (if required) a description.
-
Go to the "Topic" tab.
-
Select the application that the message should be sent to from the "Application" drop-down list.
-
Select the topic that the message should be sent to from the "Topic" drop-down list.
The topic can be subscribed to in the browser. Compare sections 2. Create topic and 3. Define appearance in the portal.Please note: If you are using a WebSocket action, you only need the name of a topic to be able to refer to it.
If you are using a Groovy script action, you need the GUID of a topic to be able to refer to it.
Send message after the transaction commit
This checkbox can be used to control whether the message should be sent after a successfully completed transaction (commit) or even if there was a rollback transaction.
-
Go to the "Content" tab.
-
Create the content for the message.
You can choose from the following options here:Name
Description
Static text
You can write a static text here. This is suitable if the message is always the same, i.e. you do not require changing message elements.
Text from data field
For a dynamic display of alternative texts, select a data field that provides the value here. This option is only available if the process contains a data group event handler.
Text from system value
You can generate texts from system values here. For example, you can apply user values or variables from the sharedState.
Generate from Velocity
You can generate texts via Velocity script here.
-
Go to the "Error handling" tab.
Define how Intrexx should behave if no (message) content can be found to continue processing.
You can choose from the following options here:Name
Description
Cancel transaction (default)
If you select this option, the transaction will be canceled Meaning that the process will no longer be executed if the WebSocket action does not have any content. In this case, a message is not sent to the selected topic.
Continue transaction
Continue transactionIf you select this option, the transaction is continued.
Select this option if subsequent process actions should still be executed even if the WebSocket action does not have any content.
This option can also be useful if the data record that triggered the event should be saved. -
Click on "OK".
You have configured a WebSocket action.
Configure Groovy script action
WebSocket actions are configured in the "Processes" module.
Requirements/preparations
In the normal manner, add a Groovy action to the corresponding process.
Step-by-step guide
To configure a Groovy action with WebSocket functions, please proceed as follows:
-
Open the properties dialog of the Groovy action.
-
Go to the "Script" tab.
-
Click on "Open Intrexx editor".
This will launch the Intrexx Groovy editor. -
Enter the Groovy script.
You can create the WebSocket message and the link to the topic using Groovy script. -
Import the Groovy script class:
de.uplanet.lucy.server.websocket.groovy.GroovyWebSocketTopic
-
Use the following Groovy function to send text or JSON messages, respectively:
GroovyWebSocketTopic.sendTextMessage GroovyWebSocketTopic.sendJsonMessage