zoukankan      html  css  js  c++  java
  • ASYNCAPI

    https://www.asyncapi.com

    Introduction

    AsyncAPI provides a specification that allows you to define Message-Driven APIs in a machine-readable format. It’s protocol-agnostic, so you can use it for APIs that work over MQTT, AMQP, WebSockets, STOMP, etc. The spec is very similar to OpenAPI/Swagger so, if you’re familiar with them, AsyncAPI should be easy for you.

    A basic example

    The following example describes a very simple streetlights service. It describes a service you can connect at api.streetlights.smartylighting.com (port 1883 or 8883) and allows you to publish information about environmental lighting conditions.

    asyncapi: '1.0.0'
    info:
    title: Streetlights API
    version: '1.0'
    description: |
    The Smartylighting Streetlights API allows you
    to remotely manage the city lights.
    license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'
    baseTopic: smartylighting.streetlights.1.0
     
    servers:
    - url: api.streetlights.smartylighting.com:{port}
    scheme: mqtt
    description: Test broker
    variables:
    port:
    description: Secure connection (TLS) is available through port 8883.
    default: '1883'
    enum:
    - '1883'
    - '8883'
     
    topics:
    event.{streetlightId}.lighting.measured:
    publish:
    $ref: '#/components/messages/lightMeasured'
     
    components:
    messages:
    lightMeasured:
    summary: Inform about environmental lighting conditions for a particular streetlight.
    payload:
    type: object
    properties:
    lumens:
    type: integer
    minimum: 0
    description: Light intensity measured in lumens.
    sentAt:
    $ref: "#/components/schemas/sentAt"
     
    schemas:
    sentAt:
    type: string
    format: date-time
    description: Date and time when the message was sent.

    If you are familiar with the OpenAPI specification, I’m sure you already found lots of similarities. But, what’s this topics section in the file? And what’s this event.{streetlightId}.lighting.measured? Let’s dive into it!

    Core concepts

    The AsyncAPI specification assumes two core concepts:

    1. Messages

    Consumer(s) communicate with your API via messages. A message is a piece of information two or more programs exchange. Most of the times to notify the other end(s) that, either an event has occurred or you want to trigger a command.

    Technically speaking the events and actions will always be sent in the same way. These are just messages, and their content can be anything. So when we talk about the difference between events and actions, this is only a semantic differentiation of message’s content. We do not enforce you to make any difference between them, although we encourage you to do it.

    A message can contain headers and a payload. However, both are optional. The specification allows you to define any header, to remain as much protocol-agnostic as possible.

    2. Topics

    Message-driven protocols usually contain something called topic (MQTT), routing key (AMQP), destination (STOMP), etc. To some extent, they can compare to URLs in HTTP APIs. So, when you send a message to your API, it will be routed depending on the topic you published on. This feature allows you to create APIs that subscribe to specific topics and publish to other ones.

  • 相关阅读:
    SQL字符串操作汇总
    重构之道清除代码异味
    Html.Action和Html.RederAction来创建子视图
    C#实现Thrift连接池[新]
    CentOS下配置Apache反向代理出错的解决
    entity framework实体用数据库默认值的方法
    为IEnumerable类型添加Add方法
    一个对Entity Framework数据层的封装
    将.netFramework4.5/MVC4/EF5/Oracle网站发布到Server2008/iis7的痛苦经历
    让vs2012运行vs2010插件的方法
  • 原文地址:https://www.cnblogs.com/dadadechengzi/p/10073161.html
Copyright © 2011-2022 走看看