Publishing and consuming documents

Tutorial to publish and consume messages by using documents.

About this task

Publishing and consuming messages by using documents involves the following high-level tasks:

  1. Create a topic, todays_quote.
  2. Create a document type, doc_quote from scratch to publish.
  3. Create a publisher flow service, publish_doc_quote, to publish a document.
  4. Create a consumer flow service, consume_doc_quote, that logs the same data that is sent in the published document.
  5. Create a subscriber, todays_quote_subscriber, to consume messages that are published to the topic.
  6. Create a consumer workflow, todays_quote_subscriber2, that logs the same data that is sent in the published document.
  7. Run the publisher flow service and check whether both the consumers ran successfully.

Creating topics

Procedure

  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 Topics.
    The Topics page is displayed.
  5. Click Add Topic.
    The New topic page is displayed.
  6. Enter the topic name as, todays_quote.
  7. Save the topic. The newly created topic details appear.

Creating document types

Procedure

  1. Go to Configurations > Flow service > Document Types > Add Document Type.
    The Add new Document type dialog box is displayed.
  2. Select Build from scratch.
  3. Click OK.
    The Add new Document type page is displayed.
  4. Click Load JSON.
    The Type or paste JSON content text box is displayed.
  5. Paste the content.
  6. Click Load JSON.
    The Add new Document type page is displayed.
  7. Click Save.
    The newly created document type is displayed under Document Types.

Creating publishers

Procedure

  1. Click Integrations > Flow services.
    The Flow services page is displayed.
  2. Click Add.
    The Start creating the Flow service page is displayed.
  3. The Start creating the Flow service page is displayed.
  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 options:
    1. Action - publish
    2. Destination type - Topic
    3. Destination - todays_quote
    4. Account - Default account
  7. Click Define I/O.
    The Define input and output fields page is displayed.
  8. Select the Add a new set option.
    The data fields appear.
  9. Enter the following details:
    1. Name - quote
    2. Type - Document Reference
    3. Document reference - doc_quote
  10. Click Done.
    The Flow service page is displayed.
  11. Click Pipeline to map the input and output fields.
    The Pipeline page is displayed.
  12. Map the quote document reference from the input pipeline to the data field in the JMS message body.
  13. Click Save.
  14. Close the Pipeline page.
    The flow service page is displayed.
  15. Click Save.
    The flow service is ready to publish messages.

Creating consumer flow service

Procedure

  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 consume_doc_quote.
  4. Enter a short description of the flow service under the flow service name.
  5. Click Define I/O.
    The Define input and output fields page is displayed.
  6. Select Specification Reference.
  7. Select Messaging Service.
  8. Click Done.
    The flow service page is displayed.
  9. Do the following steps to retrieve fields of the published quote document, you must first map the data to doc_quote in the transform pipeline step.
    1. Type Transform in the flow service step 1 and select Transform Pipeline from the list that is displayed.
    2. Click Map to map the input and output fields.
      The Pipeline page is displayed.
    3. Click Add in the Pipeline Output.
      The Pipeline output page is displayed.
    4. Enter the following details:
      1. Name - doc_quote
      2. Type - Document Reference
      3. Document reference - doc_quote
    5. Click Save.
      The Pipeline page is displayed.
    6. Map the data field under the JMSMessage body to the newly created doc_quote field.
    7. Close the Pipeline page.
      The flow service page is displayed.
  10. Do the following step to log the quote that is received.
    1. Type logCustomMessage in the flow service step 1.
    2. Click Pipleline to map the input and output fields.
      The Pipeline panel is displayed.
    3. Double-click message under the Input column.
      The Set Value page is displayed.
    4. Add the custom message: Today's quote is "%/doc_quote/content%", by "%/doc_quote/author%.
    5. Select Perform pipeline variable substitution.
    6. Click Save.
      The Pipeline page is displayed.
  11. Close the Pipeline page.
    The flow service page is displayed.
  12. Click Save.

Creating subscribers

About this task

Create a subscriber, todays_quote_subscriber, for consuming the messages sent to the topic todays_quote.

Procedure

  1. Go to Events > Messaging.
  2. Click Add new subscriber.
    The New subscriber page is displayed.
  3. Enter the following details:
    1. Subscriber Name - todays_quote_subscriber
    2. Description - Consumes messages from todays_quote
    3. Connector Type - Messaging
    4. Account - Account that must be used to connect to the messaging provider. It is the DefaultAccount.
    5. Destination type - Topic
    6. Select destination - todays_quote
    7. Invocation type - Flow service
    8. Select invocation - consume_doc_quote
  4. Click Save. The subscriber is created.

Creating consumer workflows

About this task

Create another subscriber, todays_quote_subscriber2, for consuming the messages sent to the topic, todays_quote.

Procedure

  1. Click Integrations > Workflows.
    The Workflows page is displayed.
  2. Click Add.
    The Start Building your Workflow page is displayed.
  3. Click Create New Workflow to start creating a Workflow for subscribing messages.
    The Workflow canvas is displayed.
  4. Click the Settings icon on the Start step.
    The Trigger page is displayed.
  5. Search and select the Messaging Service trigger.
  6. Click Next.
    The Messaging Service page is displayed.
  7. Do the following steps to add a subscriber:
    1. Click Add.
      The Add subscriber page is displayed.
    2. Enter the following values:
      1. Subscriber Name - todays_quote_subscriber2
      2. Description - Consumes messages that are received from todays_quote
      3. Destination type - Topic
      4. Destination - todays_quote
    3. Click Save.
      The subscriber is created.
  8. Click Save.
    The Test trigger page is displayed.
    Note: 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.
  9. Open the publisher flow service publish_doc_quote in a separate tab.
  10. Click Run.
    The Input values page is displayed.
  11. Click Run.
    The Run Successful message is displayed if the flow service runs successfully.
  12. Go to the previous tab where the consume_doc_quote_workflow is open.
  13. Click Test.
    The OUTPUT tab contains the document that was published in the earlier step.
  14. Click Done.
    The Workflow canvas is displayed.
  15. Search for the Logger connector and drag and drop the Logger connector on to the canvas.
  16. Click the warning icon on the Logger.
    The Logger page is displayed.
  17. Click Next.
    The Logger fields appear. The quote document is available in the JMS message body data fields.
  18. Paste the following text in the log data box Today's quote is "{{$trigger.JMSMessage.body.data.content}}" by {{$trigger.JMSMessage.body.data.author}}.
  19. Click Next.
    The Test this action page is displayed.
  20. Click Done.
    The Workflow canvas is displayed.
  21. Connect Logger to the Stop step.
  22. Provide a name and description for the Workflow.
  23. Save the Workflow.

Publishing messages

Procedure

  1. Open the publish_doc_quote flowservice.
  2. Click Run.
    The Input values page is displayed.
  3. Add input values for the _id, content, author, authorid, and length fields.
  4. Click Run.
    The Run Successful message is displayed if the flow service runs successfully. The document is published to the topic.
  5. Go to Monitor > Execution results > Flow service execution.
    The flow service execution statistics appear. The message is logged.
  6. Go to Monitor > Execution results > Workflow execution.
    The Workflow execution statistics appear.
  7. Select the logger step to see the log message.