AsyncAPI 3.1.0 دستاویز لکھنا: channels، messages اور operations کو جوڑنا
AsyncAPI دستاویز message-driven API کا machine-readable معاہدہ ہے۔ یہ ایپ کے سرورز، استعمال ہونے والے channels، تبادلہ ہونے والے messages اور دستاویز میں بیان کردہ ایپ کے send یا receive عمل کو بیان کرتا ہے۔ یہ مثال signup event وصول کرنے والے consumer کی ہے۔ یہ شائع شدہ AsyncAPI 3.1.0 specification کے مطابق ہے؛ host، topic اور fields فرضی ہیں۔
AsyncAPI دستاویز message-driven API کا machine-readable معاہدہ ہے۔ یہ ایپ کے سرورز، استعمال ہونے والے channels، تبادلہ ہونے والے messages اور دستاویز میں بیان کردہ ایپ کے send یا receive عمل کو بیان کرتا ہے۔ یہ مثال signup event وصول کرنے والے consumer کی ہے۔ یہ شائع شدہ AsyncAPI 3.1.0 specification کے مطابق ہے؛ host، topic اور fields فرضی ہیں۔
تین تصورات الگ رکھیں
**Channel** پتہ رکھنے والا communication point ہے۔ key دستاویز کا ID ہے، جبکہ `address` اصل runtime topic، routing key، event type یا path ہے۔ دونوں مختلف ہو سکتے ہیں۔
**Message** payload اور اختیاری application headers کی وضاحت کرتا ہے۔ payload کو AsyncAPI schema سے بیان کیا جا سکتا ہے۔
**Operation** بتاتا ہے کہ دستاویز والی application channel کے ذریعے کیا کرتی ہے۔ v3 میں `action: receive`) یا `send`) اسی application کے نقطۂ نظر سے ہوتا ہے۔
AsyncAPI 3 channels، messages اور operations کو الگ کرتا ہے تاکہ کئی operations ایک channel کا حوالہ دے سکیں۔ components کی تعریفیں معاہدے کا حصہ صرف تب بنتی ہیں جب انہیں دوسری جگہ سے refer کیا جائے۔
Consumer دستاویز کی مثال
یہ YAML Kafka topic سے JSON signup events وصول کرنے والی application بیان کرتا ہے۔ یہ broker configure نہیں کرتا، رسائی نہیں دیتا اور consumer code نہیں بناتا۔
asyncapi: 3.1.0
info:
title: صارف اندراج وصول کرنے والا consumer
version: 1.0.0
defaultContentType: application/json
servers:
production:
host: broker.example.com:9092
protocol: kafka
channels:
userSignupChannel:
address: user.signedup
messages:
userSignup:
$ref: '#/components/messages/UserSignup'
operations:
receiveUserSignup:
action: receive
channel:
$ref: '#/channels/userSignupChannel'
messages:
- $ref: '#/channels/userSignupChannel/messages/userSignup'
components:
messages:
UserSignup:
name: UserSignup
title: صارف کا اندراج
summary: نئے اندراج کی اطلاع دیتا ہے
contentType: application/json
payload:
type: object
additionalProperties: false
required: [eventId, userId, occurredAt]
properties:
eventId:
type: string
userId:
type: string
occurredAt:
type: string
format: date-timeاوپر کا asyncapi specification version ہے؛ info.version) API description کا version ہے۔ userSignupChannel دستاویزی ID ہے اور user.signedup) اصل address۔ دوبارہ استعمال ہونے والا message components.messages میں متعین ہے اور channel اسے refer کرتا ہے۔ Operation channel کا حوالہ دیتا ہے؛ اگر messages) درج ہو تو اسی channel کے message کو refer کرنا چاہیے۔ اسے چھوڑنے پر operation channel کے تمام messages process کرتا ہے۔
سمت اور دائرہ جانچیں
صرف اس وجہ سے consumer کے operation کو send) نہ سمجھیں کہ broker یا producer event شائع کرتا ہے۔ ہر application کو اپنے نقطۂ نظر سے بیان کریں؛ specification receiver دستاویز کو sender سے مشینی طور پر اخذ کرنے کی سفارش نہیں کرتی۔ address نامعلوم ہو تو اسے چھوڑ دیں یا null لکھیں، گھڑیں نہیں۔ Bindings صرف protocol-specific تفصیل دیتے ہیں؛ عمومی معاہدہ broker کی ترتیب، delivery ضمانت، دوبارہ کوشش، retention یا runtime رویہ متعین نہیں کرتا۔
دستاویز کی تصدیق
تصدیق کریں کہ pin کیا ہوا parser، validator، Studio یا generator AsyncAPI 3.1.0 کو سپورٹ کرتا ہے؛ 2.x tool کو v3-compatible نہ سمجھیں۔
channel IDs اور addresses، اور ہر operation کی action و channel reference دیکھیں۔
اگر operation میں `messages`) ہو تو ہر حوالہ اسی channel کے message کی طرف ہو۔
payload مثالوں کو schema سے ملائیں اور operational policies الگ درج کریں۔
پروجیکٹ کے pin کردہ validator/CLI کو چلائیں۔ پہلے version اور reference errors درست کریں؛ درست دستاویز broker connection یا application behavior ثابت نہیں کرتی۔
کامیابی کا مطلب ہے کہ منتخب tool اسے 3.1.0 کے طور پر parse کرے اور channel، message اور operation references باہم مربوط ہوں۔ یہ مثال validator یا broker پر نہیں چلائی گئی۔
ذرائع
[AsyncAPI Specification 3.1.0](https://www.asyncapi.com/docs/reference/specification/v3.1.0)
[AsyncAPI document structure](https://www.asyncapi.com/docs/concepts/asyncapi-document/structure)
[Adding messages](https://www.asyncapi.com/docs/concepts/asyncapi-document/adding-messages)
[Migrating from AsyncAPI 2.x to 3.x](https://www.asyncapi.com/docs/migration/migrating-to-v3)