diff --git a/README.md b/README.md index 5bbcec3..a840a33 100644 --- a/README.md +++ b/README.md @@ -129,12 +129,12 @@ To run the generated Java project in a Docker container, use the commands as bel 1. Build the image ``` docker build -t [PACKAGE_NAME]:[VERSION] . - ``` + ``` 2. Run the image in detached mode ``` - docker run -d [PACKAGE_NAME]:[VERSION] - ``` + docker run -d [PACKAGE_NAME]:[VERSION] + ``` For further information including network setup, please see the [tutorial](template/TUTORIAL.md). diff --git a/TUTORIAL.md b/TUTORIAL.md index a55fdf5..65cbb52 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -29,7 +29,7 @@ cd ~/asyncapi-java-tutorial ``` ## Running the Publisher/Subscriber Template -These commands will allow you to run the Java Template publisher/subscriber model using IBM MQ. +These commands will allow you to run the Java Template publisher/subscriber model using IBM MQ. 1. Run the AsyncAPI Generator.
**Note:** You may need to change the username and password values if you have not followed the IBM MQ tutorial. ``` ag https://ibm.biz/mq-asyncapi-yml-sample https://ibm.biz/mq-asyncapi-java-template -o ./output -p server=production -p user=app -p password=passw0rd @@ -44,7 +44,7 @@ These commands will allow you to run the Java Template publisher/subscriber mode ``` 3. Install the dependencies required to run this template ``` - mvn compile + mvn compile ``` 4. Create .jar package using maven ``` @@ -54,7 +54,7 @@ These commands will allow you to run the Java Template publisher/subscriber mode ``` java -cp target/asyncapi-java-generator-0.1.0.jar com.ibm.mq.samples.jms.DemoSubscriber ``` -6. In a seperate terminal, navigate to the `output` directory above and run your generated Publisher +6. In a seperate terminal, navigate to the `output` directory above and run your generated Publisher ``` cd ~/asyncapi-java-tutorial/output java -cp target/asyncapi-java-generator-0.1.0.jar com.ibm.mq.samples.jms.DemoProducer @@ -79,27 +79,27 @@ To deploy a dockerised instance of this project; 1. Build the image ``` docker build -t [PACKAGE_NAME]:[VERSION] . - ``` + ``` 2. Run the image in detached mode ``` docker run -d [PACKAGE_NAME]:[VERSION] - ``` + ``` -Please note; The default `Dockerfile` included in output will only run `DemoSubscriber.java`. This will need to be replaced with the entrypoint to your application. +Please note; The default `Dockerfile` included in output will only run `DemoSubscriber.java`. This will need to be replaced with the entrypoint to your application. ### Networking -Docker networking needs to be properly configured in order to allow your project to connect to an MQ instance. +Docker networking needs to be properly configured in order to allow your project to connect to an MQ instance. If MQ is also running in a docker container 1. Create a docker network ``` docker network create exampleMqNetwork - ``` + ``` 2. Attach the docker network to your MQ container ``` docker network connect exampleMqNetwork - ``` + ``` 3. Update your env.json server hostname to match the container name for MQ. To find the name run ``` docker ps diff --git a/components/Common.js b/components/Common.js index 12d9fca..698ce54 100644 --- a/components/Common.js +++ b/components/Common.js @@ -17,7 +17,7 @@ import { createJavaArgsFromProperties } from '../utils/Types.utils'; export function Class({ childrenContent, name, implementsClass, extendsClass }) { - if (childrenContent === undefined) { + if (childrenContent === undefined) { childrenContent = ''; } @@ -73,17 +73,17 @@ export function getMqValues(url, val) { } const splitVals = regString.toString().split('/'); - if (splitVals.length === 2) { + if (splitVals.length === 2) { if (val === 'qmgr') return splitVals[0]; if (val === 'mqChannel') return splitVals[1]; - + throw new Error('Invalid parameter passed into getMqValues function'); } throw new Error('Invalid URL passed into getMqValues function'); } - + export function URLtoHost(url) { const u = new URL(url); return u.host; @@ -154,7 +154,7 @@ import ${params.package}.models.${messageName.charAt(0).toUpperCase() + messageN /* Used to resolve a channel object to message name */ export function ChannelToMessage(channel, asyncapi) { // Get payload from either publish or subscribe - const targetPayloadProperties = Object.prototype.hasOwnProperty.call(channel, 'publish') ? + const targetPayloadProperties = Object.prototype.hasOwnProperty.call(channel, 'publish') ? channel.publish().message().payload().properties() : channel.subscribe().message().payload().properties(); diff --git a/components/Consumer/MQConsumer.js b/components/Consumer/MQConsumer.js index 2a9442e..7d7d503 100644 --- a/components/Consumer/MQConsumer.js +++ b/components/Consumer/MQConsumer.js @@ -79,7 +79,7 @@ export function ReceiveMessage({ message }) { * Implement your business logic to handle * received messages here. */ - + } catch (JMSException jmsex) { recordFailure(jmsex); } catch (JsonProcessingException jsonproex) { @@ -101,7 +101,7 @@ export function ReceiveMessage({ message }) { } `; } - + export function ConsumerConstructor({ name }) { return ` super(); diff --git a/components/Files/Consumers.js b/components/Files/Consumers.js index 0876252..b36f9f9 100644 --- a/components/Files/Consumers.js +++ b/components/Files/Consumers.js @@ -27,16 +27,16 @@ export function Consumers(asyncapi, channels, params) { const packagePath = javaPackageToPath(params.package); const message = ChannelToMessage(channel, asyncapi); - + if (channel.subscribe()) { return ( - + - + @@ -45,8 +45,8 @@ export function Consumers(asyncapi, channels, params) { - + ); } }); -} +} \ No newline at end of file diff --git a/components/Files/Producers.js b/components/Files/Producers.js index a444d7e..da9f0b1 100644 --- a/components/Files/Producers.js +++ b/components/Files/Producers.js @@ -29,14 +29,14 @@ export function Producers(asyncapi, channels, params) { if (channel.publish()) { return ( - + - + - + diff --git a/components/PomHelper.js b/components/PomHelper.js index cc505f6..8e0b098 100644 --- a/components/PomHelper.js +++ b/components/PomHelper.js @@ -22,7 +22,7 @@ export function PomHelper({ server, params }) { // Resolve additional dependencies depending on protocol supplied const supportedProtocol = server.protocol(); const dependencies = resolveDependencies(supportedProtocol); - + let protocolDependencies = ''; for (const dependency of dependencies) { diff --git a/components/Producer/MQProducer.js b/components/Producer/MQProducer.js index 53d65c9..062942a 100644 --- a/components/Producer/MQProducer.js +++ b/components/Producer/MQProducer.js @@ -22,24 +22,24 @@ export function ProducerDeclaration() { export function SendMessage() { return ` - public void send(ModelContract modelContract) { + public void send(ModelContract modelContract) { Serializable modelInstance = (Serializable) modelContract; try{ // JSON encode and transmit ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(modelInstance); - + logger.info("Sending Message: " + json); - + this.producer.send(destination, json); - + }catch (JsonProcessingException e){ logger.severe("An error occured whilst attempting to send a message: " + e); } }`; } - + export function ProducerConstructor({ name }) { return ` super(); @@ -81,9 +81,9 @@ import ${params.package}.Connection; import ${params.package}.PubSubBase; import ${params.package}.models.ModelContract; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.annotation.JsonView; `; -} +} \ No newline at end of file diff --git a/components/PubSubBase/MQPubSubBase.js b/components/PubSubBase/MQPubSubBase.js index 0250541..7944861 100644 --- a/components/PubSubBase/MQPubSubBase.js +++ b/components/PubSubBase/MQPubSubBase.js @@ -25,22 +25,22 @@ function getPubSubContent(params) { import java.util.Map; import java.util.List; import java.nio.file.Paths; - import com.fasterxml.jackson.databind.ObjectMapper; - import com.fasterxml.jackson.databind.ObjectWriter; + import com.fasterxml.jackson.databind.ObjectMapper; + import com.fasterxml.jackson.databind.ObjectWriter; import ${params.package}.ConnectionHelper; import ${params.package}.LoggingHelper; - + import javax.jms.Destination; import javax.jms.JMSContext; import javax.jms.JMSRuntimeException; import javax.jms.JMSException; - - + + public class PubSubBase { - + protected static final Logger logger = Logger.getLogger("${params.package}"); - + protected ConnectionHelper ch = null; protected JMSContext context = null; protected Destination destination = null; @@ -49,25 +49,25 @@ function getPubSubContent(params) { public void Base(){ LoggingHelper.init(logger); } - + public void createConnection(String topicName, String id){ // Retrieve first MQ endpoint from env.json List MQ_ENDPOINTS = null; Map MQFirst = null; - + try { ObjectMapper mapper = new ObjectMapper(); - + // Convert JSON file to map Map> map = mapper.readValue(Paths.get("env.json").toFile(), Map.class); MQ_ENDPOINTS = map.get("MQ_ENDPOINTS"); // TODO : Allow switching between multiple endpoints MQFirst = MQ_ENDPOINTS.get(0); - + } catch (Exception ex) { ex.printStackTrace(); } - + // Create connection definition from env variables Connection myConnection = new Connection( MQFirst.get("HOST").toString(), @@ -79,26 +79,26 @@ function getPubSubContent(params) { null, topicName, null); - + // Build connection helper ch = new ConnectionHelper(id, myConnection); - + logger.info("created connection factory"); - + // Create context and set local topic destination context = ch.getContext(); logger.info("context created"); - + destination = ch.getTopicDestination(); - + logger.info("destination created"); } - + public void close() { ch.closeContext(); ch = null; } - + protected void recordFailure(Exception ex) { if (ex != null) { if (ex instanceof JMSException) { @@ -108,16 +108,16 @@ function getPubSubContent(params) { } } } - + protected void processJMSException(JMSException jmsex) { logger.warning(jmsex.getMessage()); Throwable innerException = jmsex.getLinkedException(); logger.warning("Exception is: " + jmsex); - + if (innerException != null) { logger.warning("Inner exception(s):"); } - + while (innerException != null) { logger.warning(innerException.getMessage()); innerException = innerException.getCause(); @@ -125,7 +125,7 @@ function getPubSubContent(params) { return; } } - + `; } diff --git a/components/demo/DemoProducer.js b/components/demo/DemoProducer.js index d43829e..9d84cd2 100644 --- a/components/demo/DemoProducer.js +++ b/components/demo/DemoProducer.js @@ -14,8 +14,8 @@ * limitations under the License. */ -/* -* Here you can see example of complex operations. +/* +* Here you can see example of complex operations. * You can actually do whatever you want. It is important that the value returned from the function must be a string or a component. */ diff --git a/components/demo/DemoSubscriber.js b/components/demo/DemoSubscriber.js index 175bfe5..d5a263f 100644 --- a/components/demo/DemoSubscriber.js +++ b/components/demo/DemoSubscriber.js @@ -14,8 +14,8 @@ * limitations under the License. */ -/* -* Here you can see example of complex operations. +/* +* Here you can see example of complex operations. * You can actually do whatever you want. It is important that the value returned from the function must be a string or a component. */ @@ -31,7 +31,7 @@ public class DemoSubscriber { public static void main(String[] args) { // Create a subscriber instance to connect to the server ${className}Subscriber consumer = new ${className}Subscriber(); - + // Receive updates for this queue indefinitely consumer.receive(TIMEOUT); @@ -39,4 +39,4 @@ public class DemoSubscriber { consumer.close(); } }`; -} +} \ No newline at end of file diff --git a/components/readme/MQReadme.js b/components/readme/MQReadme.js index f4da9c3..c63edd8 100644 --- a/components/readme/MQReadme.js +++ b/components/readme/MQReadme.js @@ -7,11 +7,11 @@ ${asyncapi.info().description()} For instructions on installing maven for your operating system, please see the [Apache Maven site](https://maven.apache.org/install.html). ## Running the Publisher/Subscriber template -These commands will allow you to run the template publisher/subscriber model using IBM MQ. +These commands will allow you to run the template publisher/subscriber model using IBM MQ. 1. Install dependencies \`\`\`sh - mvn compile + mvn compile \`\`\` This command uses maven to install all the required dependences needed for this template to run. @@ -28,17 +28,17 @@ These commands will allow you to run the template publisher/subscriber model usi java -cp target/asyncapi-java-generator-0.1.0.jar: ${params.package}.DemoProducer \`\`\` - This command runs the publisher function of this template from the generated .jar file. + This command runs the publisher function of this template from the generated .jar file. -4. In a seperate terminal, Run Subscriber +4. In a seperate terminal, Run Subscriber \`\`\`sh java -cp target/asyncapi-java-generator-0.1.0.jar: ${params.package}.DemoSubscriber \`\`\` - This command runs the subscriber function of this template from the generated .jar file. + This command runs the subscriber function of this template from the generated .jar file. The messages should now be sent from the running publisher to the running subscriber, using MQ topics. `; -} +} \ No newline at end of file diff --git a/template/index.js b/template/index.js index 3ce2dca..39b6040 100644 --- a/template/index.js +++ b/template/index.js @@ -16,7 +16,7 @@ import { File } from '@asyncapi/generator-react-sdk'; -// Import custom components from file +// Import custom components from file import { PackageDeclaration, EnvJson } from '../components/Common'; import { javaPackageToPath } from '../utils/String.utils'; @@ -125,4 +125,4 @@ function ReadmeRenderer(asyncapi, params) { ); -} +} \ No newline at end of file diff --git a/test/mocks/many-messages.yml b/test/mocks/many-messages.yml index 724281b..3b2788e 100644 --- a/test/mocks/many-messages.yml +++ b/test/mocks/many-messages.yml @@ -10,13 +10,13 @@ servers: description: Production Instance 1 channels: song/released: - publish: + publish: message: $ref: '#/components/messages/song' subscribe: message: $ref: '#/components/messages/song' - + components: messages: song: @@ -65,4 +65,4 @@ components: description: Artist name dob: type: string - description: Song date of birth + description: Song date of birth \ No newline at end of file diff --git a/test/mocks/single-channel.yml b/test/mocks/single-channel.yml index 61cf126..b7e5eaa 100644 --- a/test/mocks/single-channel.yml +++ b/test/mocks/single-channel.yml @@ -10,13 +10,13 @@ servers: description: Production Instance 1 channels: song/released: - publish: + publish: message: $ref: '#/components/messages/song' subscribe: message: $ref: '#/components/messages/song' - + components: messages: song: diff --git a/utils/DependencyResolver.utils.js b/utils/DependencyResolver.utils.js index 874dede..ded47aa 100644 --- a/utils/DependencyResolver.utils.js +++ b/utils/DependencyResolver.utils.js @@ -1,5 +1,5 @@ const dependencyMap = [ - { + { protocols: ['ibmmq', 'ibmmq-secure'], dependencies: [ { groupId: 'com.ibm.mq', artifactId: 'com.ibm.mq.allclient', version: '9.2.3.0' } @@ -22,4 +22,4 @@ export function resolveDependencies(protocol) { } return foundMapping.dependencies; -} +} \ No newline at end of file diff --git a/utils/Types.utils.js b/utils/Types.utils.js index 7e3d45e..dc92dfb 100644 --- a/utils/Types.utils.js +++ b/utils/Types.utils.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* +/* * Converts from async api defined types (https://www.asyncapi.com/docs/specifications/v2.0.0#dataTypeFormat) * to native Java types */ @@ -34,7 +34,7 @@ export function asyncApiTypeToJavaType(asyncApiType) { case 'string': return 'String'; - + case 'byte': return 'byte'; @@ -57,7 +57,7 @@ export function asyncApiTypeToJavaType(asyncApiType) { } } -/* +/* * Helper class to easily assign local class properties */ export function setLocalVariables(properties) { @@ -67,9 +67,9 @@ export function setLocalVariables(properties) { `; }); } - -/* - * Helper class to define variables + +/* + * Helper class to define variables */ export function defineVariablesForProperties(properties) { return Object.entries(properties).map(([name, property]) => { @@ -77,8 +77,8 @@ export function defineVariablesForProperties(properties) { }); } -/* - * Helper class to pass variables into a function defined by properties +/* + * Helper class to pass variables into a function defined by properties */ export function passJavaArgs(properties) { return Object.entries(properties).map(([name, property]) => { @@ -104,7 +104,7 @@ export function createJavaConstructorArgs(properties) { }); } -/* +/* * Generates an example value from asyncAPI datatype in Java */ export function asyncApiTypeToDemoValue(asyncApiType) {