Skip to content

Instantly share code, notes, and snippets.

Created March 23, 2021 11:49
Show Gist options
  • Save smoya/1d81a9556b8756c883c44ce873b645f1 to your computer and use it in GitHub Desktop.
Save smoya/1d81a9556b8756c883c44ce873b645f1 to your computer and use it in GitHub Desktop.
[AsyncAPI] Intent-driven API suggestion example

DISCLAIMER: Not native at JS, code has not been tested. Just an illustrative example.

Examples for the Parser Intent-driven API.



  • asyncapi.channelsApplicationPublishesTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe())

  • asyncapi.channelsApplicationSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasPublish())

  • asyncapi.channelsClientCanPublishTo() -> asyncapi.channels().filter(channel => channel.hasPublish())

  • asyncapi.channelsClientCanSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe())

  • asyncapi.messagesApplicationPublishesTo() -> asyncapi.channelsApplicationPublishesTo().map(function(channel) {return channel.subscribe().message};)

  • asyncapi.messagesApplicationSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasPublish()).map(function(channel) {return channel.publish().message};)

  • asyncapi.messagesClientCanPublishTo() -> asyncapi.channels().filter(channel => channel.hasPublish()).map(function(channel) {return channel.publish().message};)

  • asyncapi.messagesClientCanSubscribeTo() -> asyncapi.channels().filter(channel => channel.hasSubscribe()).map(function(channel) {return channel.subscribe().message};)

Getters (we still keep them)

  • message.getOperations() (Due to the current spec, only one operation is linked to a particular message)
  • message.getPayload()


  • asyncapi.bindings('kafka') -> Return all the bindings from all possible places:
    • servers
    • channels
    • operations
    • messages
  • asyncapi.bindings('kafka', 'servers') -> Return kafka binding for servers
  • asyncapi.bindings('kafka', 'servers', 'name-of-server1', 'name-of-server2') -> Return kafka binding for specific servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment