Tutorial to publish and subscribe messages by using topics and workflows.
About this task
Publishing and subscribing messages by using topics and workflows involves the following
high-level tasks:
- Creating publishers - Create a workflow, T1_publish_workflow to publish
the messages to topic T1.
- Creating subscribers - Create a Subscriber, T1_subscriber, which
subscribes to T1 and runs a workflow,
T1_subscriber_workflow, to consume the messages.
- Publishing messages - Run the publisher and view the consumer workflow execution logs.
Procedure
- Creating publishers
- In Projects, create a project. For example,
Messaging_Ops. You can also select an existing project.
- Click
.
The Workflows page is displayed.
- Click Add.
The Start Building your
Workflow page is displayed.
- Click Create New Workflow to start creating a workflow to
publish the message.
The Workflow canvas is displayed.
- Drag and drop the Messaging connector on to the canvas from the
right-side Search box.
- Click the warning icon on the Messaging connector.
The Messaging page is displayed.
- Provide the following details to configure the Messaging
connector:
- Select action - publish
- Name - T1_publisher
- Destination Type - Topic
- Destination - T1 (You can also add a new
destination by clicking Add.
- Connect to Messaging - DefaultAccount
- Click Next. The T1_publisher page is displayed.
- Type the message, Hello! I’m publishing a message, in the
string field.
- Click Next. The Test this action page is displayed.
- Click Test. The Output tab shows that the message
has been posted.
- Click Done. The workflow canvas page is displayed.
- Connect the Messaging step to the Stop
button.
- Provide a name for the workflow,
T1_publisher_workflow.
- Click Done.
The workflow name is
updated.
- Save the workflow.
- Creating subscribers
- Click.
The
Workflows page is displayed.
- Click Add.
The Start Building your
Workflow page is displayed.
- Click Create New Workflow to start creating a workflow for
subscribing messages.
The workflow canvas is displayed.
- Click the Settings icon on the Start
step.
The Trigger page is displayed.
- Search and select the Messaging Service
trigger.
- Click Next.
The Messaging Service
page is displayed.
- Do the following steps to add a subscriber.
- Click Add. The Add subscriber page is
displayed.
- Enter the following values:
- Subscriber Name - T1_subscriber
- Description - Consumes messages that are received from
T1
- Destination type: Topic.
- Destination: T1
- Click Save. The subscriber is created.
- Do the following to add filters.
- Click Add Filters. The filter fields appear.
- Enter the following details. Repeat this step to add more filters.
- Name - F1.
- Filter Expression -
%body/string%==”Hello”.
- Click Save.
The Test
trigger page is displayed. If you want to test the trigger, you must first publish a
message and then click the Test button to see whether the message is
received.
- Click Skip.
The Trigger output
data page is displayed.
- Click Done.
The workflow canvas is
displayed.
- Search for the Logger connector and drag and drop the
Logger connector on to the canvas.
- Click the warning icon on the Logger.
The
Logger page is displayed.
- Click Next.
The Logger fields
appear.
- Drag and drop string to the Log Data
field.
- Click Next.
The Test this
action page is displayed.
- Click Done.
The workflow canvas is
displayed.
- Connect the Logger to the Stop
step.
- Provide a name and description for the workflow.
- Save the workflow.
Now, the workflow is ready to receive messages
and process further steps based on the filters specified.
- Publishing messages
- Open the T1_publish_workflow from the
Workflows page.
- Click Run.
- Go to .
The
workflow execution statistics appear. You can observe that the
Execution
source column for the:
- T1_subscriber_workflow is Trigger.
- T1_publisher_workflow is Manual.
In this way, you can publish and subscribe messages by using workflows.