Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This article describes how to implement a JS7 workflow with two shell jobs that communicate over a Message Queue Service (MQ). These jobs include one job for publishing and one job for receiving and executing JS7 - REST Web Service API calls.

The document explains which classes and methods have to be created and their respective purposes. This example is has been developed for use with https://activemq.apache.org/.

...

The use case includes the following steps:

  1. Run Running a shell job that which executes a Java class on an Agent which . This sends a JSON body to a Message Queue (MQ) 
  2. Run Running a shell job that which executes a Java class on an Agent which . This receives a JSON body from a Message Queue and executes a JS7 REST Web Service API call with the given JSON body.

...

This article shows the workflow configuration with the sample implementation as explained with in the JS7 - Example - How to send and receive messages with a JMS Message Queue Service article.

...

Download the library used in this example: js7-jms-example-jar.zip.
The archive contains:

  • the js7-jms-example-js7.jar used in this example.,
  • the js7-jms-example.config configuration file a configuration file named js7_jms.config containing credentials for the connection and information about the workflow to start.

Download the workflow configuration (upload .json):  js7-jms_-example_-workflow.zip.

Prerequisites

For this example the The activemq-all-5.15.0.jar library is used for this example.

  • Either download the .jar file from the Active MQ web site and add it to the class path
  • or, in the case of a Maven project, add the following dependency to the project configuration.

Code Block
languagexml
titleMaven dependency for activemq-all
collapsetrue
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.15.0</version>
</dependency>
  • Adjust the js7-jms-example.config configuration file to your own environment.

language
Code Block
phptitleJMS configuration file: js7_-jms_config-example.config
linenumberstrue
collapsetrue
# Message Queue ServerService Settings
jms_url             = tcp://localhost:61616
jms_queue_name      = test
jms_time_to_live    = 5000 

# JS7 JOC Cockpit Settings
joc_api_url         = http://localhost:4444/joc/api/
username            = root
password            = root

# /orders/add API Settings
controller_id       = standalonejs7
workflow_path       = /JS7Demo/01_HelloWorld/jdHelloWorld

myWorkflowToStart

Workflow

The workflow in this example includes two jobs which both call the main class of the JmsExample.java class with either a produce or a consume argument.

  • the produce argument determines specifies the use of a SOSProducer to publish a message (JSON body) to a Message Queue Service.
  • the consume argument determines specifies the use of a SOSConsumer to read a message (JSON body) from a Message Queue Service andto:
    • login to the JS7 REST Web Service API,
    to
    • send the API call /orders/add with the body received from the Message Queue Service and finally to
    • logout.

The Java executable has to be included in the PATH environment variable or the Java call has to be adjusted with to include the path to the Java executable.

Note
Make sure that the configuration file js7_-jms-example.config configuration file from the archive is stored in the same path as the library js7-jms-example-js7.jar library used in the workflow.
Code Block
languagejs
titleWorkflow Configuration
linenumberstruejms_test
collapsetrue
{
  "version": "1.1.0",
  "timeZone": "Europe/Berlin",
  "instructions": [
    {
      "TYPE": "Execute.Named",
      "jobName": "producer_job",
      "label": "job_produce"
    },
    {
      "TYPE": "Execute.Named",
      "jobName": "consumer_job",
      "label": "job_consume"
    }
  ],
  "jobs": {
    "producer_job": {
      "agentName": "standaloneAgent",
      "executable": {
        "TYPE": "ShellScriptExecutable",
        "script": "java -jar C:/tmp/js7-jms-example-js7.jar produce",
        "v1Compatible": false
      },
      "skipIfNoAdmissionForOrderDay": false,
      "parallelism": 1,
      "graceTimeout": 15,
      "failOnErrWritten": false,
      "warnOnErrWritten": false,
      "title": "produce"
    },
    "consumer_job": {
      "agentName": "standaloneAgent",
      "executable": {
        "TYPE": "ShellScriptExecutable",
        "script": "java -jar C:/tmp/js7-jms-example-js7.jar consume",
        "v1Compatible": false
      },
      "skipIfNoAdmissionForOrderDay": false,
      "parallelism": 1,
      "graceTimeout": 15,
      "failOnErrWritten": false,
      "warnOnErrWritten": false,
      "title": "consumer"
    }
  }
}

...