0.3.2 • Published 29 days ago

@asyncapi/java-template v0.3.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
29 days ago

AsyncAPI Java Generator

Overview

This template generates Java application code based from an AsyncAPI document.

Implementations are provided for the following protocols:

Technical requirements

Supported protocols

  • ibmmq
    • This is implemented using the JMS API with the correct jars, in this case ibmmq was chosen. The use of JMS allows allows the template to be extensible to other providers by providing the correct jars at the Maven stage.
  • kafka
    • This is implemented using the official client library from the Apache Kafka project.

How to use the template

This template must be used with the AsyncAPI Generator. You can find all available options here.

CLI

# Install the AsyncAPI Generator
npm install -g @asyncapi/generator

# Run generation
ag https://ibm.biz/mq-asyncapi-yml-sample @asyncapi/java-template -o output -p server=production

Template Tutorial

For complete instructions on generating the Java and subsequently using it to send messages, please see the relevant tutorial:

Template configuration

You can configure this template by passing different parameters in the Generator CLI: -p PARAM1_NAME=PARAM1_VALUE -p PARAM2_NAME=PARAM2_VALUE

NameDescriptionRequiredDefault
serverServer must be defined in yaml and selected when using the generatorYes-
userUser for the server to generate code for. This can also be provided as an environment variable (see below)Noapp
passwordPassword for the server to generate code for. This can also be provided as an environment variable (see below)Nopassw0rd
packageJava package name for generated codeNocom.asyncapi
mqTopicPrefixMQ topic prefix. Used for ibmmq protocols. Default will work with dev MQ instanceNodev//
asyncapiFileDirCustom output location of the AsyncAPI file that you provided as an inputNoThe root of the output directory

Environment variables

Credentials can be provided as environment variables if preferred. If set, these credentials will override those set with the template parameters.

NameDescription
APP_USEROverrides user template parameter
APP_PASSWORDOverrides password template parameter

All credentials are stored in env.json in the output directory, so they can be updated at any time without needing to run the generator or recompile the Java.

Development

The most straightforward command to use this template is:

ag https://ibm.biz/mq-asyncapi-yml-sample @asyncapi/java-template -o output -p server=production

For local development, you need different variations of this command. First of all, you need to know about three important CLI flags:

  • --debug enables the debug mode in Nunjucks engine what makes filters debugging simpler.
  • --watch-template enables a watcher of changes that you make in the template. It regenerates your template whenever it detects a change.
  • --install enforces reinstallation of the template.

There are two ways you can work on template development:

  • Use global Generator and template from your local sources:
    # assumption is that you run this command from the root of your template
    ag https://ibm.biz/mq-asyncapi-yml-sample @asyncapi/java-template -o output -p server=production
  • Use Generator from sources and template also from local sources. This approach enables more debugging options with awesome console.log in the Generator sources or even the Parser located in node_modules of the Generator:
    # assumption is that you run this command from the root of your template
    # assumption is that generator sources are cloned on the same level as the template
    ../generator/cli.js https://ibm.biz/mq-asyncapi-yml-sample @asyncapi/java-template -o output -p server=production

Key Files

As a developer, you may want to make changes to how the generator operates. This non-exhaustive list aims to show the files you will likely need to change most.

Generator Code

PathDescription
template/index.jsEntry point for the application
components/Common.jsCommon/helper functions used across the generator
utils/*Contains all filters
components/*Contains reusable components

Generated Code

Note: Files in the output directory are generated using the ag command, detailed in the above section.

PathDescription
output/env.jsonUsed for setting environmental variables such as username and password
output/com/asyncapi/PubSubBase.javaThe base used for generated publishers and subscribers

Container Information

To run the generated Java project in a Docker container, use the commands as below:

  1. Build the image

     docker build -t [PACKAGE_NAME]:[VERSION] .
  2. Run the image in detached mode

     docker run -d [PACKAGE_NAME]:[VERSION]

For further information including network setup, please see the tutorial.

Future Enhancements

  • General enhancements
    • Add support for multiple messages per channel (ofMany)
    • Support for MQTT
    • Support for other protocols
  • ibmmq protocol enhancements
    • Add support for TLS connections
    • Add support for more JMS Types alongside JMS Text
    • Offer Java event listener support for consumers

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

0.3.2

29 days ago

0.3.1

2 months ago

0.3.0

2 months ago

0.2.10

2 months ago

0.2.9

3 months ago

0.2.8

3 months ago

0.2.7

3 months ago

0.2.6

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

9 months ago

0.2.1

1 year ago

0.1.2

2 years ago

0.2.0

1 year ago

0.1.3

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago