Overview
AsyncAPI calls allow you to interact with message brokers and event-driven systems, supporting protocols like AMQP, Kafka, MQTT, WebSocket, and more.Properties
The AsyncAPI document that defines the operation to call.Can reference AsyncAPI 2.6.0 or 3.0.0 specifications.
The name of the channel on which to perform the operation.Used only for AsyncAPI v2.6.0.The operation to perform is defined by declaring either
message (publish) or subscription (subscribe).A reference to the AsyncAPI operation to call.Used only for AsyncAPI v3.0.0.
An object used to configure the server to call the specified AsyncAPI operation on.If not set, defaults to the first server matching the operation’s channel.
The protocol to use to select the target server.Ignored if
server has been set.Supported values: amqp, amqp1, anypointmq, googlepubsub, http, ibmmq, jms, kafka, mercure, mqtt, mqtt5, nats, pulsar, redis, sns, solace, sqs, stomp, wsAn object used to configure the message to publish using the target operation.Required if
subscription has not been set.An object used to configure the subscription to messages consumed using the target operation.Required if
message has not been set.The authentication policy, or the name of the authentication policy, to use when calling the AsyncAPI operation.
AsyncAPI Server
Configures the target server:The name of the server to call the specified AsyncAPI operation on.
The target server’s variables, if any.
AsyncAPI Outbound Message
Configures a message to publish:The message’s payload, if any.
The message’s headers, if any.
AsyncAPI Subscription
Configures a subscription to messages:A runtime expression used to filter consumed messages.
An object used to configure the subscription’s lifetime.
Configures the iterator, if any, for processing each consumed message.
Subscription Lifetime
The amount of messages to consume.Required if
while and until have not been set.The duration that defines for how long to consume messages.
A runtime expression used to determine whether or not to keep consuming messages.Required if
amount and until have not been set.A runtime expression used to determine until when to consume messages.Required if
amount and while have not been set.Examples
Publishing a Message
Subscribing to Messages (Amount)
Subscribing Until Condition
Subscribing While Condition
Processing Each Message
With Authentication
Kafka Example
Supported Protocols
AsyncAPI supports a wide range of protocols:- AMQP/AMQP1 - Advanced Message Queuing Protocol
- Kafka - Distributed event streaming platform
- MQTT/MQTT5 - Lightweight messaging for IoT
- WebSocket (ws) - Full-duplex communication
- HTTP - Standard web protocol
- NATS - Cloud-native messaging system
- Redis - In-memory data structure store
- And more…
Subscription Output
An AsyncAPI subscribe operation produces a sequentially ordered array of all the messages it has consumed, potentially transformed usingforeach.output.as.
Best Practices
- Use Filters: Apply filters to consume only relevant messages
- Set Timeouts: Always set a timeout with
consume.forto prevent indefinite subscriptions - Handle Errors: Wrap AsyncAPI calls in try/catch blocks for robust error handling
- Version Documents: Keep AsyncAPI documents versioned and accessible
- Process Incrementally: Use
foreachto process messages one at a time for better error handling
Related
- OpenAPI Protocol - For synchronous API calls
- HTTP Protocol - For direct HTTP requests
- Listen Task - For listening to CloudEvents
- Authentication - Authentication schemes for AsyncAPI