All Projects → asyncapi → go-watermill-template

asyncapi / go-watermill-template

Licence: Apache-2.0 license
Go template for the AsyncAPI Generator using Watermill module

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to go-watermill-template

Watermill
Building event-driven applications the easy way in Go.
Stars: ✭ 3,504 (+9121.05%)
Mutual labels:  watermill
java-spring-cloud-stream-template
Java Spring Cloud Stream template for the AsyncAPI Generator
Stars: ✭ 26 (-31.58%)
Mutual labels:  asyncapi
nodejs-template
Node.js template for the AsyncAPI Generator
Stars: ✭ 19 (-50%)
Mutual labels:  asyncapi
converter-go
Convert AsyncAPI documents from older to newer versions with Golang
Stars: ✭ 17 (-55.26%)
Mutual labels:  asyncapi
asynction
SocketIO python framework driven by the AsyncAPI specification. Built on top of Flask-SocketIO. Inspired by Connexion.
Stars: ✭ 40 (+5.26%)
Mutual labels:  asyncapi
event-gateway
AsyncAPI Event Gateway
Stars: ✭ 35 (-7.89%)
Mutual labels:  asyncapi
watermill-amqp
AMQP Pub/Sub for the Watermill project.
Stars: ✭ 27 (-28.95%)
Mutual labels:  watermill
modelina
Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents.
Stars: ✭ 55 (+44.74%)
Mutual labels:  asyncapi
jasyncapi
/jay-sync-api/ is a Java code-first tool for AsyncAPI specification
Stars: ✭ 29 (-23.68%)
Mutual labels:  asyncapi
nestjs-asyncapi
Async API module for Nestjs that provides documentation generation using your existing code (similar to Nestjs swagger module)
Stars: ✭ 22 (-42.11%)
Mutual labels:  asyncapi
parser-go
It parses AsyncAPI documents.
Stars: ✭ 43 (+13.16%)
Mutual labels:  asyncapi
openapi-filter
Filter internal paths, operations, parameters, schemas etc from OpenAPI/Swagger/AsyncAPI definitions
Stars: ✭ 112 (+194.74%)
Mutual labels:  asyncapi
python-paho-template
Python Paho template for the AsyncAPI generator
Stars: ✭ 17 (-55.26%)
Mutual labels:  asyncapi
java-spring-template
Java Spring template for the AsyncAPI Generator
Stars: ✭ 41 (+7.89%)
Mutual labels:  asyncapi
boats
Beautiful Open Api Template System
Stars: ✭ 28 (-26.32%)
Mutual labels:  asyncapi
watermill-http
HTTP Pub/Sub for the Watermill project.
Stars: ✭ 16 (-57.89%)
Mutual labels:  watermill
html-template
HTML template for AsyncAPI Generator
Stars: ✭ 38 (+0%)
Mutual labels:  asyncapi
Spec
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
Stars: ✭ 1,860 (+4794.74%)
Mutual labels:  asyncapi
home
This is the home page for the API specification toolbox.
Stars: ✭ 16 (-57.89%)
Mutual labels:  asyncapi
wsapix
Next generation Websocket framework for nodejs
Stars: ✭ 17 (-55.26%)
Mutual labels:  asyncapi

AsyncAPI logo

Overview

This template generates a Go module that uses watermill as library for building event-driven applications. The reason to choose watermill is because it provides an abstraction to messaging supporting multiple protocols. This will help this generator support multiple protocols.

Template Output

The go code generated by this template has the following structure

  • asyncapi
    • handlers.go -- handlers for publishers and subscribers
    • payloads.go -- generated go structs using Modelina
    • publishers.go
    • router.go -- configures watermill router, needed only for subscribers
    • server.go -- server config
    • subscribers.go
  • go.mod
  • go.sum
  • main.go

Technical requirements

Async API Requirements

To have correctly generated code, your AsyncAPI file MUST define operationId for every operation.

Example:

channels:
  light/measured:
    subscribe:
      operationId: LumenPublish

Supported protocols

Protocol Subscriber Publishers
AMQP Yes Yes

How to use the template

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

CLI

This template has been tested to generate an AMQP subscriber for this asyncapi.yaml file

Run the following command to generate a Go module

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

Following are the options that can be passed to the generator

  1. moduleName: name of the go module to be generated

How to use the generated code

The above code currently generates a Go 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 OR docker
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 to execute the code run
go run main.go
  1. Running local instance of rabbitmq, navigate to it using http://localhost:15672/ with username and password guest/ guest (These are default rabbitmq credentials). FYI one can start an instance of rabbitmq using docker as follow
    docker run -d -p 15672:15672 -p 5672:5672 rabbitmq:3-management
    
  2. Create a queue as per the AsyncAPI spec. This can be done either of the following ways
    • Using the UI: Refer to this article that walks through the process of how this can be done in the UI / RabbitMQ Admin
    • cURL request. Default rabbitmq user is guest and password is guest
     curl --user <rabbit-user>:<rabbit-password> -X PUT \
       http://localhost:15672/api/queues/%2f/<queue-name> \
       -H 'cache-control: no-cache' \
       -H 'content-type: application/json' \
       -d '{
     "auto_delete":false,
     "durable":true
     }'
    
  3. Publish a message to the queue as per the AsyncAPI spec. This can be done either of the following ways
    • Using the UI: Refer to this article that walks through the process of how this can be done in the UI / RabbitMQ Admin
    • cURL request. Default rabbitmq user is guest and password is guest
     curl --user <rabbit-user>:<rabbit-password> -X POST \
       http://localhost:15672/api/exchanges/%2f/amq.default/publish \
       -H 'cache-control: no-cache' \
       -H 'content-type: application/json' \
       -d ' {
     "properties":{},
     "routing_key":"light/measured",
     "payload":"{\"id\":1,\"lumens\":2,\"sentAt\":\"2021-09-21\"}",
     "payload_encoding":"string"
     }'
    
  4. Check the output at the terminal where go run main.go was running and the published message should be printed

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

Name Description Required Example
moduleName Name for the generated Go module false my-app

Contribution guide

If you are interested in contributing to this repo refer to the contributing docs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].