Socket
Book a DemoInstallSign in
Socket

@asyncapi/java-spring-template

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/java-spring-template

Java Spring template for AsyncAPI generator.

Source
npmnpm
Version
0.14.0
Version published
Weekly downloads
1.8K
7.69%
Maintainers
3
Weekly downloads
 
Created
Source

Java Spring generator

All Contributors

Use your AsyncAPI definition to generate java code to subscribe and publish messages

Usage

AsyncAPI definitions

In order for the generator to know what names to use for some methods it's necessary to make use of AsyncAPI specification bindings. here is an example of how to use it:

channels:
  event.lighting.measured:
    publish:
      bindings:
        kafka:
          groupId: my-group
      message:
         $ref: '#/components/messages/lightMeasured'
    subscribe:
      message:
        $ref: '#/components/messages/lightMeasured'

here is a complete example

asyncapi: '2.0.0'
info:
  title: Streetlights API
  version: '1.0.0'
  description: |
    The Smartylighting Streetlights API allows you
    to remotely manage the city lights.
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'

servers:
  production:
    url: api.streetlights.smartylighting.com:{port}
    protocol: mqtt
    variables:
      port:
        default: '1883'
        enum:
          - '1883'
          - '8883'

channels:
  event.lighting.measured:
    publish:
      bindings:
        kafka:
          groupId: my-group
      message:
        $ref: '#/components/messages/lightMeasured'
    subscribe:
      message:
        $ref: '#/components/messages/lightMeasured'
components:
  messages:
    lightMeasured:
      summary: Inform about environmental lighting conditions for a particular streetlight.
      payload:
        $ref: "#/components/schemas/lightMeasuredPayload"
  schemas:
    lightMeasuredPayload:
      type: object
      properties:
        lumens:
          type: integer
          minimum: 0
          description: Light intensity measured in lumens.
        sentAt:
          $ref: "#/components/schemas/sentAt"
    sentAt:
      type: string
      format: date-time
      description: Date and time when the message was sent.

From the command-line interface (CLI)

  Usage: ag [options] <asyncapi> @asyncapi/java-spring-template

  Options:

    -V, --version                 output the version number
    -o, --output <outputDir>       directory where to put the generated files (defaults to current directory)
    -p, --param <name=value>       additional param to pass to templates
    -h, --help                    output usage information

Supported parameters

NameDescriptionRequiredDefault
listenerPollTimeoutOnly for Kafka. Timeout in ms to use when polling the consumer.No3000
listenerConcurrencyOnly for Kafka. Number of threads to run in the listener containers.No3
asyncapiFileDirPath where original AsyncAPI file will be stored.Nosrc/main/resources/api/

Examples

The shortest possible syntax:

ag asyncapi.yaml @asyncapi/java-spring-template

Specify where to put the result and define poll timeout:

ag -o ./src asyncapi.yaml -p listenerPollTimeout=5000 @asyncapi/java-spring-template

If you don't have the AsyncAPI Generator installed, you can install it like this:

npm install -g @asyncapi/generator

Run it

Go to the root folder of the generated code and run this command (you need the JDK1.8):

./gradlew bootRun

Generated source contains RabbitMQ docker-compose. So you could use it to test amqp with:

docker-compose -f src/main/docker/rabbitmq.yml up -d

Missing features

See the list of features that are still missing in the component:

  • support of Kafka is done based on clear "spring-kafka" library without integration like for mqtt or amqp
  • generated code for protocols mqtt and amqp could be out of date. Please have a look to application.yaml and AmqpConfig.java, MqttConfig.java
  • tests are not provided
  • add annotation to the model generation. Consider "@Valid", "@JsonProperty", "@Size", "@NotNull" e.t.c.
  • parameters for topics are not supported
  • server variables are not entirely supported
  • security schemas are not supported
  • traits are not supported
  • Json serializer/desirializer is used always, without taking into account real content type
  • client side generation mode (in general just flip subscribe and publish channels)
  • template generation of docker-compose depending on protocol of server, now the rabbitmq is hardcoded

If you want to help us develop them, feel free to contribute.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Semen

📖 💻

Francesco Nobilia

👀

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

Keywords

asyncapi

FAQs

Package last updated on 22 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts