Tutorial to publish and subscribe messages by using queues and flow services.
About this task
Publishing and subscribing messages by using queues and flow services involves the following
high-level tasks:
- Creating queues - Create a queue Q1 to store messages received from
publisher.
- Creating publisher - Create a flow service, Q1_publish_flowservice to publish the
messages to Q1.
- Creating subscriber - Create a subscriber, Q1_subscriber, which subscribes to
Q1 and runs a flow service, Q1_consume_flowservice, to consume the messages.
- Publishing messages - Run the publisher and view the consumer flow service execution
logs.
Procedure
- Create a queue.
- In projects, create a project, for example, Messaging_Ops. You
can also select an existing project.
- Go to
.
- Click Messaging destinations.
The
Queues page is displayed.
- Click Add Queue.
The New
Queue page is displayed.
- Enter the queue name as Q1.
- Click Save.
The newly created queue is
displayed.
- Creating publishers
- Click .
The Flow services page is
displayed.
- Click Add.
The Start creating the
Flow service page is displayed.
- Enter the Flow service name as
Q1_publisher_flowservice.
- Enter a short description of the flow service under the flow service
name.
- Type Messaging in the flow service step 1 and select
Messaging from the list that is displayed.
The fields that
are associated with the Messaging application is
displayed.
- Select the following values:
- Action - publish
- Destination type - Queue
- Destination - Q1
- Account - Default account
- Click Pipeline to map the input and output fields.
The Pipeline page is displayed.
- Double-click the string field.
The
Set Value page is displayed.
- Enter the message I want to publish a message!.
- Click Save.
The Pipeline
page is displayed.
- Close the Pipeline page.
The Flow
service page is displayed.
- Click Save.
The flow service is ready to
publish messages.
- Creating subscribers
You can create the consumer flow service in one of the following ways:
- Create a flow service from the Flow services page, then assign that flow
service to a subscriber during subscriber creation.
- Create the flow service when creating a subscriber.
Here, the steps are explained to create Q1_subscriber containing
Q1_consume_flowservice from the Subscribers page.
- Go to
.
- Click Add new subscriber.
The New
subscriber page is displayed.
- Enter the following values:
- Subscriber Name - Q1_subscriber
- Description - Consumes messages from Q1
- Connector Type - Messaging
- Account - Account that must be used to connect to the messaging provider.
It is the DefaultAccount.
- Destination type - Queue
- Select destination - Q1
- Specify the following values to set the default invocation:
- Invocation type - Flow service
- Select invocation: Click Add and enter the name as
Q1_consumer_flowservice in the New Flow service
page.
- Click Save.
- Do the following to add routing rules:
Repeat the sub steps in this step to
add more rules if needed.
- Click Add routing rules.
The New
routing rule page is displayed.
- Enter the following values:
- Name - Rule 1
- Filter -
%body/string%==”Hello”
- Invocation type - Flow service
- Select Invocation - Click Add and enter the name
as Rule1_invocation_flowservice in the New Flow service
page.
- Click Save. If the incoming message criterion is satisfied, the selected
flow service is added and is started.
Note: You can choose an existing flow service too. Only flow services that have JMS
trigger specifications are listed in the Select Invocation field.
- Click Add.
The new rule is created and listed
under Routing rules
- Click Save.
The flow service is added to the
subscriber and the Subscriber details page is displayed. Further, as you
created the consumer flow service from the Subscribers page, the trigger
specification reference is displayed automatically.
- Click Save.
The subscriber is created with
the Q1_consumer_flowservice that consumes messages that arrive in
Q1.
- Publishing messages
- Open the Q1_publisher_flowservice.
- Click Run.
If the
Q1_publisher_flowservice runs successfully, the
Q1_consumer_flowservice runs automatically. The
Q1_publisher_flowservice sends the message to the queue
Q1 and as the Q1_Subscriber is listening to
Q1, it runs the Q1_consumer_flowservice created in the
Q1_Subscriber.
- Go to .
The flow service execution statistics page is
displayed.
- Go to the Executions section. You can observe that the
Execution source column for,
- Q1_consumer_flowService is a Messaging Subscriber.
- Q1_publisher_flowService is User Interface.
In this way, you can publish and subscribe messages by using flow services.