Publishing and subscribing messages by using flow services

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:

  1. Creating queues - Create a queue Q1 to store messages received from publisher.
  2. Creating publisher - Create a flow service, Q1_publish_flowservice to publish the messages to Q1.
  3. Creating subscriber - Create a subscriber, Q1_subscriber, which subscribes to Q1 and runs a flow service, Q1_consume_flowservice, to consume the messages.
  4. Publishing messages - Run the publisher and view the consumer flow service execution logs.

Procedure

  1. Create a queue.
    1. In projects, create a project, for example, Messaging_Ops. You can also select an existing project.
    2. Go to Events > Messaging.
    3. Click Messaging destinations.
      The Queues page is displayed.
    4. Click Add Queue.
      The New Queue page is displayed.
    5. Enter the queue name as Q1.
    6. Click Save.
      The newly created queue is displayed.
  2. Creating publishers
    1. Click Integrations > Flow services.
      The Flow services page is displayed.
    2. Click Add.
      The Start creating the Flow service page is displayed.
    3. Enter the Flow service name as Q1_publisher_flowservice.
    4. Enter a short description of the flow service under the flow service name.
    5. 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.
    6. Select the following values:
      1. Action - publish
      2. Destination type - Queue
      3. Destination - Q1
      4. Account - Default account
    7. Click Pipeline to map the input and output fields.
      The Pipeline page is displayed.
    8. Double-click the string field.
      The Set Value page is displayed.
    9. Enter the message I want to publish a message!.
    10. Click Save.
      The Pipeline page is displayed.
    11. Close the Pipeline page.
      The Flow service page is displayed.
    12. Click Save.
      The flow service is ready to publish messages.
  3. 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.

    1. Go to Events > Messaging.
    2. Click Add new subscriber.
      The New subscriber page is displayed.
    3. Enter the following values:
      1. Subscriber Name - Q1_subscriber
      2. Description - Consumes messages from Q1
      3. Connector Type - Messaging
      4. Account - Account that must be used to connect to the messaging provider. It is the DefaultAccount.
      5. Destination type - Queue
      6. Select destination - Q1
    4. Specify the following values to set the default invocation:
      1. Invocation type - Flow service
      2. Select invocation: Click Add and enter the name as Q1_consumer_flowservice in the New Flow service page.
      3. Click Save.
    5. Do the following to add routing rules:
      Repeat the sub steps in this step to add more rules if needed.
    6. Click Add routing rules.
      The New routing rule page is displayed.
    7. Enter the following values:
      1. Name - Rule 1
      2. Filter - %body/string%==”Hello”
      3. Invocation type - Flow service
      4. Select Invocation - Click Add and enter the name as Rule1_invocation_flowservice in the New Flow service page.
      5. 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.
    8. Click Add.
      The new rule is created and listed under Routing rules
    9. 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.
    10. Click Save.
      The subscriber is created with the Q1_consumer_flowservice that consumes messages that arrive in Q1.
  4. Publishing messages
    1. Open the Q1_publisher_flowservice.
    2. 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.
    3. Go to Monitor > Execution results > Flow service execution.
      The flow service execution statistics page is displayed.
    4. 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.