Git Product home page Git Product logo

golang-watermill-template's Introduction

Overview

This template generates a go lang module that uses watermill as the messaging middleware

Technical requirements

Specification requirements

The table contains information on parts of the specification required by this template to generate the proper output.

Property name Reason Fallback Default
components.schemas This template supports only schemas that have unique and human-readable names. Such names can also be provided if schemas are described under components.schemas and each schema is a separate object with its unique key. - -

Supported protocols

Currently this template supports AMQP subscribers

How to use the template

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

CLI

As of this initial commit this template has been tested to generate an AMQP subscriber for the following asyncapi.yml file

asyncapi: '2.1.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'

defaultContentType: application/json

servers:
  local:
    url: localhost:5672
    protocol: amqp
    security:
      - user-password: []

channels:
  light/measured:
    bindings:
      amqp:
        is: routingKey
        queue:
          name: light/measured
          durable: true
          exclusive: true
          autoDelete: false
          vhost: /
        bindingVersion: 0.2.0
    publish:
      summary: Inform about environmental lighting conditions for a particular streetlight.
      operationId: onLightMeasured
      message:
        name: LightMeasured
        payload:
          $id: LightMeasured
          additionalProperties: false
          type: object
          properties:
            id:
              type: integer
              minimum: 0
              description: Id of the streetlight.
            lumens:
              type: integer
              minimum: 0
              description: Light intensity measured in lumens.
            sentAt:
              type: string
              format: date-time
              description: Date and time when the message was sent.

components:
  securitySchemes:
    user-password:
      type: userPassword

Run the following command to generate a golang module

npm install -g @asyncapi/generator
# clone this repository and navigate to this repository
ag /path/to/asyncapi.yaml ./ -o /path/to/generated-code -p moduleName=your-go-module-name

How to use the generated code

The above code currently generates a golang module that has a AMQP subscriber.

Pre-requisites

To run the generated code the following needs to be installed

  1. go 1.16 +
  2. rabbitmq-server
Running the code
  1. Navigate to the path where the code was generated
  2. Run the following commands to download the dependencies
go mod download
go mod tidy
  1. Currently the code does not utilize the server bindings to generate the server URI. It is currently hardcoded to point to a local instance of rabbitmq. It is hardcoded as "amqp://guest:guest@localhost:5672/" at <generated-code>/config/server.go. Change it as per your rabbitmq instance requirements
  2. Finally navigate to the root folder of the generated code and run
go run main.go
  1. If you have a local instance of rabbitmq, navigate to it using http://localhost:15672/ with username and password guest/ guest (These are default rabbitmq credentials).
  2. Create a queue as per the async api spec
  3. Publish a message to the queue as per the async api spec
  4. Check the output at the terminal where go run main.go was running and the published message should be printed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.