- Overview
- Technical requirements
- Specification requirements
- Supported protocols
- How to use the template
- Template configuration
- Custom hooks that you can disable
- Development
- Contributors
This template generates a go lang module that uses watermill as the messaging middleware
- 1.1.0 =< Generator < 2.0.0,
- Generator specific 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. |
- | - |
Currently this template supports AMQP subscribers
This template must be used with the AsyncAPI Generator. You can find all available options here.
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
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
The above code currently generates a golang module that has a AMQP subscriber.
To run the generated code the following needs to be installed
- go 1.16 +
- rabbitmq-server
- Navigate to the path where the code was generated
- Run the following commands to download the dependencies
go mod download
go mod tidy
- 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 - Finally navigate to the root folder of the generated code and run
go run main.go
- If you have a local instance of
rabbitmq
, navigate to it usinghttp://localhost:15672/
with username and passwordguest
/guest
(These are default rabbitmq credentials). - Create a queue as per the async api spec
- Publish a message to the queue as per the async api spec
- Check the output at the terminal where
go run main.go
was running and the published message should be printed