我想从AsyncAPI规范中生成代码,并尝试一下它的工作原理。我的目标是为每个客户端打开一个套接字,并通过该连接发送/接收不同类型的消息。我找不到任何例子来告诉我如何生成代码并运行它。
这是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然后,我使用https://github.com/asyncapi/generator从以下yaml生成java代码
ag asyncapi.yaml @asyncapi/java-spring-template这就是我被困的地方,它使用stuck框架消息传递,我不知道如何在使用生成的消息处理程序的同时配置/实现它。或者我在yaml中遗漏了什么东西,所以它不能正常生成。
https://stackoverflow.com/questions/71177019
复制相似问题