Connections to the Test MQTT Broker are only available
when encrypted. In the first step, please import the self-signed certificate
from the server into the
portal properties.
In the "Certificate store" dialog, select the option "Download from internet address".
Enter the server "message-broker.unitedplanet.com" and the port 8883 there
for MQTT.
2. Read messages
The topic "guest/sampleMachine/machineState", which logs the status of a machine,
is on the Test MQTT Broker. Here, we will demonstrate how you
can read messages from this topic and write them to an Intrexx application.
Switch to the edit page. Delete all of the existing elements except the buttons.
Then create the following new
edit fields
with the
"Text" control type:
Device Operational Status
Message Title
Switch to the "All Entries" and add the new fields as
table columns.
The "Creation date" data field can be added for sorting. The existing column
"Title" can be removed. Save and publish the application.
Remove all process elements, which may already be in the process. Then create
a Generic event source.
In the configuration
select the class
"de.uplanet.lucy.server.mqtt.workflow.eventsource.MQTTWorkflowEventSource".
Add the following properties:
When a generic MQTT event source is configured and the process is published,
a connection to the Message Broker is established immediately.
Select the generic event source and open the "Details" dialog by pressing F4.
There, copy the GUID of the event
source to the clipboard.
Then create a Generic event handler.
In the configuration
select the class
"de.uplanet.lucy.server.mqtt.workflow.eventhandler.MQTTWorkflowEventHandler".
Add the property "MQTTSourceGuid". Add the copied GUID of the event source
as the value. This connects the generic event handler to the generic
event source, meaning it will listen out for events provided by this source.
Now create a Groovy action
and connect it to the generic event handler.
Insert the following script there:
In this script, the values of the machine status (deviceOperationalStatus)
and the message titles (messagesTitle) are requested and
assigned to the sharedState.
Create a Data group action
and connect it to the Groovy action. Select the action "Add record".
On the Field assignment tab,
add the user-defined system values "deviceOperationalStatus" and "messagesTitle",
whose values are transmitted to the sharedState in the preceding Groovy action,
and select the "Processing context" type. Assign the system values to the
corresponding target fields from the application. Save the process.
2.3. The application in the browser
If you open the application in the browser, you will now see the protocol of
the machine status, if and when changes have been made on the
Test MQTT Broker. Every time a change is made on the Broker, a new
data record with the current data will be created in the application
by the process.
Switch to the "All Entries" and add the new field as a
table column.
The "Creation date" data field can be added for sorting.
Save and publish the application.
Replace the GUID "78A3E6FCB1CB525C159079D97DADA7BAE21F0CC4"
with the GUID of the "Title" data field from your application.
You can ascertain this GUID in the editor in the
Application structure
area and insert it directly.
In this script, a reference to the Title data field from the
application created earlier is made.
In the second line, the current value of the data field is written to the
sharedState.
Create a Generic action and
connect it to the Groovy action. In the properties, select the class
"de.uplanet.lucy.server.mqtt.workflow.action.MQTTMessageProducerWorkflowAction"
and define the following properties:
data.contextVariableName, Value "urn:sharedState:msgOut"
serverUri, Value "ssl://message-broker.unitedplanet.com:8883"
topic, Value "guest/[any topic name]"
userName, Value "extuser"
password, Value "haithabu"
With this part of the process, the value of the "Title" data field
is written to the topic "guest/[your topic name]" when you
change one of the application's data records in the browser.
3.2.2. Excursus: Context variables
Dynamic values from the current processing context can be used as well
as static values for the property "data.contextVariableName"
of the generic action.
The following prefixes are supported:
To check whether writing messages on the Test MQTT Broker
works correctly, a reading process chain can be created in addition.
Follow the same steps as described in 3.2.2. Create process
but with the following differences:
The process chain is created in the current process. You
do not need to create an additional process.
In the generic event source, use the userName "extuser" instead of "guest".
Add another property "password" with the value "haithabu".
Use the topic name, which you defined in the generic action
in the first process chain (guest/[any topic name]), for the property
"topic".
On the "Field assignment" tab of the data group action, add the
user-defined system value "msg" with "Processing context" as the type
and assign this to the data field "Read" from the application
created earlier.
Save the process.
The entire process should now look something like this:
3.3. The application in the browser
On the edit page, enter a random title. This title can then be modified
on the "All Entries" page by clicking on the magnifying glass symbol
in the first column of the table. This change triggers the process
that writes the change to the broker. The second process chain responds
and writes the changed value in a new data record that you can then
immediately see in the table on the "All Entries" page.
4. Classes
4.1. MQTTWorkflowEventSource
The class "MQTTWorkflowEventSource" makes messages from one or more
MQTT topics available. Click
here
for more information about the class and the properties described below.
Property: serverUri
Mandatory. The connection URI for the MQTT server needs to be entered as
the value (e.g. ssl://message-broker.unitedplanet.com:8883).
Property: topic
Mandatory. The MQTT topic that should be consumed needs to be entered
as the value (e.g. guest/sampleMachine/machineState).
Click here
for more information.
Property: userName
Enter the username for logging in to the server as the value here.
Property: password
Enter the password for the user logging in to the server as the value here.
Property: clientId
Client identifier
that identifies the MQTT client against the server. This property usually
does not need to be defined as Intrexx automatically generates a unique client ID.
Property: randomizeClientId
If the value is true (default), a globally unique suffix will
be added to the configured client ID.
impersonateUserGuid is a standard property for
event sources or timers.
Here, enter the GUID of the
user,
who should be used to perform this event source, as the value. If
a user GUID is not provided, the processes are performed with the
system account and administrative permissions.
Property: runWithLocalSystemPrivileges
runWithLocalSystemPrivileges (default: true) is a standard property for
event sources or timers.
It defines whether the process shoul be performed with
administrative permissions.
Property: logVerbose
More detailed logging (default: false).
Property: reconnect
This property (default: true) controls whether the client (meaning this event
source) should try to reconnect to the server if the connection is broken.
Property: sendBeforeStartEvent
Defines whether an event should be generated before the event source
is initiated (default: false).
Property: sendAfterStopEvent
Defines whether an event should be generated after the event source
is finished (default: false).
Property: startDelay
Is a standard property for many
event sources or timers.
Determines the latency in milliseconds before the event source
is initiated (default: 0).
Property: onErrorRestartWaitTimeout
#
Latency in milliseconds before restarting work after an error (default: 60 seconds = 60000 ms).
Property: stopWaitTimeout
Latency in milliseconds before closing the connection.
4.2. QOS
With this class, the MQTT
Quality of Service is managed.
Possible values: