'AsyncAPI Websockets Spring generated code and implementation
I want to generate code from AsyncAPI specification and try out how it works. My goal is to have only 1 socket open for each client and over that connection send/receive different types of messages. I couldnt find any example that would show me how to generate the code and run it.
Here is the API yaml
asyncapi: '2.3.0'
info:
title: demo
version: '1.0.0'
description: websocket demo
servers:
test:
url: localhost
protocol: ws
channels:
data:
publish:
operationId: publishData
message:
$ref: '#/components/messages/dataMessage'
subscribe:
operationId: subscribeData
message:
$ref: '#/components/messages/dataMessage'
components:
messages:
dataMessage:
headers:
$ref: "#/components/schemas/MessageHeader"
payload:
oneOf:
- $ref: "#/components/schemas/FirstPayloadType"
- $ref: "#/components/schemas/SecondPayloadType"
schemas:
MessageHeader:
type: object
properties:
messageType:
enum:
- a
- b
- c
FirstPayloadType:
type: object
properties:
x:
type: string
y:
type: number
SecondPayloadType:
type: object
properties:
op:
type: string
tar:
type: string
Then i use https://github.com/asyncapi/generator to generate the java code from this yaml with
ag asyncapi.yaml @asyncapi/java-spring-template
And thats where Im stuck, it uses springframework messaging and i dont know how to configure/implement it while using the generated message handler. Or maybe im missing something in the yaml so it doesnt generate properly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
