Skip to content

Let channels be identified by an ID rather than their address. #663

Closed

Description

@smoya

Context

This is part of the RFC #618 (comment).
In an effort around reducing the scope of such RFC, it has been split into several proposals so they can move forward independently.

The problem

Channels are currently identified by their address. E.g.:

channels:
  user/signedup: # this is both the address and the identifier of the channel
    description: ...

With the current approach, and once #660 happens, we will have few issues:

  • When referencing a channel, the channel identifier should match with the refereced one, otherwise the address will be different than in the referenced channel. E.g.:

    # common.yaml
    channels:
      user/signedup:
          description: ...
          
    # asyncapi.yaml
    channels:
      user/signedup: # here we have to use the same identifier as in common.yaml, otherwise the address will be different
        $ref: 'common.yaml#/components/channels/user~signedup'
  • That introduces a problem when we need to change the address of a shared channel. Let's say Kafka topic name changes. With the current approach, we need to change the address on all files that reference the user/signedup channel from common.yaml (as JSON Reference will fail as well).

  • As you may noticed, the JSON Pointer for user/signedup channel is user~1signedup. It is unexpected and you have to have some JSON Pointer knowledge or find examples to find out such format. It is very error-prone.

Suggestion

To add a new address field to the channel definition that represents the real address and not the channel identifier.
With that change, the previous example will look like:

# common.yaml
channels:
  userSignedUp:
      address: user/signedup
      description: ...
      
# asyncapi.yaml
channels:
  myUserSignedUp: # here we can add whatever ID we want. If address changes in `userSignedUp` from common.yaml, nothing will need to change in this file
    $ref: 'common.yaml#/components/channels/userSignedUp' # no slash transformation is needed in the JSON Pointer :)

Fixes #739 as well

Activity

  1. added
    💭 Strawman (RFC 0)
    on Dec 1, 2021
  2. jonaslagoni commented on Jan 19, 2022

    @jonaslagoni
    Member

    I love the move to a property, whether address is the right keyword, not so sure, but I don't have other alternatives at the moment.

    What exactly is the reason we need an ID rather than making channels an array?

    Especially now that #665 is added.

  3. smoya commented on Jan 19, 2022

    @smoya
    MemberAuthor

    I love the move to a property, whether address is the right keyword, not so sure, but I don't have other alternatives at the moment.

    What exactly is the reason we need an ID rather than making channels an array?

    Especially now that #665 is added.

    I guess the reason is that we might also allow people to reference channels not only from components but from channels at root level.
    Another thing is that you need to differentiate between servers anyway, for example, when generating code or documentation. Let's say I want to generate a websocket client but in the document, two servers are declared. How can I pick up one or another? By it's ID.

  4. jonaslagoni commented on Jan 20, 2022

    @jonaslagoni
    Member

    Okay I retract my suggestion, you are right.

    Especially if you want to define two channels operating over the same address, with slightly different behavior, you would need to add a channelId instead to differentiate them, if we had arrays.

  5. changed the title [-]Let channels be identified by an ID rather than their address.[/-] [+]feat: Let channels be identified by an ID rather than their address.[/+] on Feb 9, 2022
  6. changed the title [-]feat: Let channels be identified by an ID rather than their address.[/-] [+]feat: let channels be identified by an ID rather than their address.[/+] on Feb 9, 2022
  7. changed the title [-]feat: let channels be identified by an ID rather than their address.[/-] [+]Let channels be identified by an ID rather than their address.[/+] on Feb 9, 2022
  8. char0n commented on Feb 9, 2022

    @char0n
    Member

    Hi everybody,

    I was CCed in asyncapi/spec-json-schemas#171, so let me share my opinion as well here. IMHO I can see a couple of problems here:

    Components.channels field in defined in following way:

    image

    This means that string that forms the key can be arbitrary and doesn't have any semantics. string !== {channel}. The proof lies in following AsyncAPI definition fragment:

    components:
      channels:
        channel1:
          description: channel description
    
    channels:
      user/signup:
        $ref: "#/components/channels/channel1"

    As you can clearly see, the channel1 is just an arbitrary identifier of the channel and has nothing to do with {channel} (path).

    The only place where this is problematic is in following fragment:

    channels:
     user/logout:
       $ref: "#/channels/user~1signedup"
     user/signedup:
       description: channel description

    But as we now have reusable Components.channels field, this usecase should be discouraged and anything that is intended to be reusable should be in Components.channels. This encourages using best practices and putting stuff where it belongs. IMHO I don't think this proposal is needed (don't hate me:).

  9. magicmatatjahu commented on Feb 9, 2022

    @magicmatatjahu
    Member

    @char0n

    But as we now have reusable Components.channels field, this usecase should be discouraged and anything that is intended to be reusable should be in Components.channels. This encourages using best practices and putting stuff where it belongs. IMHO I don't think this proposal is needed (don't hate me:).

    Please look at this proposal from point of view person who need to write several AsyncAPI documents and use that same channel in few documents. Of course can make reference by:

    $ref: "#/components/channel1"

    but then needs to remember that (e.g.) "user/signup" channel address, yes? :) So that PR adds possibility to make more easier the "channels registry" and treats address as channelID :)

    Please read #618 proposal to understand why we wanna make it :) Of course "channel registry" is not the only reason, but it is one of many, perhaps the best why it makes sense.

  10. char0n commented on Feb 9, 2022

    @char0n
    Member

    Please look at this proposal from point of view person who need to write several AsyncAPI documents and use that same channel in few documents. Of course can make reference by:

    @magicmatatjahu I really did that. Where I want to get is to have AsyncAPI spec version where the only required fields are asyncapi and info. That way I can create reusable definitions that only contain stuff that is used in multiple other definition. It would look like this:

    reusable.yaml

    asyncapi: 2.3.0
    info:
      title: reusable document fragment
      version: 1.0.0
    components:
      channels:
        channel1:
          description: channel description

    Then it will be consumed by other definitions:

    definition1.yaml

    asyncapi: 2.3.0
    info:
      title: definition 1
      version: 1.0.0
    channels:
      path/to/channel:
        $ref: "./reusable.yaml/#components/channels/channel1"

    definition2.yaml

    asyncapi: 2.3.0
    info:
      title: definition 2
      version: 1.0.0
    channels:
      path/to/channel:
        $ref: "./reusable.yaml/#components/channels/channel1"

    This is currently not possible as AsyncAPI.channels field is currently required (this requires small backward compatible change to support) . My opinion on this is influenced by heavy usage of OpenAPI and doing exactly the stuff that I describe here using OpenAPI.

    Please read #618 proposal to understand why we wanna make it :) Of course "channel registry" is not the only reason, but it is one of many, perhaps the best why it makes sense.

    #618 is super long ;] I'm trying to look at this change introduced in this issue in isolated way. People have full ability to create keys as they seem fit and can use a lot of imagination to come up with the key names that are sometimes exotic. This issue IMHO tries to resolve one particular issue which is resolvable by other means (small change in spec + recommended practices).

  11. magicmatatjahu commented on Feb 9, 2022

    @magicmatatjahu
    Member

    This is currently not possible as AsyncAPI.channels field is currently required (this requires small backward compatible change to support) . My opinion on this is influenced by heavy usage of OpenAPI and doing exactly the stuff that I describe here using OpenAPI.

    Please read #618 proposal to understand why we wanna make it :) Of course "channel registry" is not the only reason, but it is one of many, perhaps the best why it makes sense.

    #618 is super long ;] I'm trying to look at this change introduced in this issue in isolated way. People have full ability to create keys as they seem fit and can use a lot of imagination to come up with the key names that are sometimes exotic. This issue IMHO tries to resolve one particular issue which is resolvable by other means (small change in spec + recommended practices).

    Yeah, exactly, currently it's not possible. Changing it is easy (to make channels options) but we need for that 3.0.0.

    Maybe I don't understand the second paragraph (sorry!), but a channel key and an address are two completely different things in my opinion. I understand that the keys may be different, but this should be just "information" for the developer, not for a user reading the documentation. It's a bit like a server url - it may have a different key but url identifies its "uniqueness" and so it is with the channel address.

    recommended practices

    And this is probably the problem, because it is better to solve this at the level of specification and not through recommended practices. There are things that should be recommended, but if there is an option to fix it in the specification itself, then let's go the second way. As I wrote, currently the problem are references and people then have to remember that a given channel should have a given key in the .channels field (exactly address).

    Of course, lets wait for others opinion, but I understand in this way the changes that @fmilas proposed and @smoya introduced :)

  12. magicmatatjahu commented on Feb 9, 2022

    @magicmatatjahu
    Member

    Additionally, one may wonder how to overwrite such an address if we want to have something like a channel but without the address? We can create a Channel Trait Object, just like we have a Message Trait Object and an Operation Trait Object, where address will be optional.

  13. char0n commented on Feb 9, 2022

    @char0n
    Member

    Maybe I don't understand the second paragraph (sorry!), but a channel key and an address are two completely different things in my opinion. I understand that the keys may be different, but this should be just "information" for the developer, not for a user reading the documentation. It's a bit like a server url - it may have a different key but url identifies its "uniqueness" and so it is with the channel address.

    Don't worry; It's definitely me (not being clear). What I tried to say was this:

    asyncapi: 2.3.0
    info:
      title: reusable document fragment
      version: 1.0.0
    components:
      channels:
        user/signup:
          description: channel description
    channels:
      user/signup:
        $ref: #/components/channels/user~1signup

    People can still use (and probably will) slashes in keys that represents reusable channels. I do understand the argument thought, that this proposal tries to avoid it as much as possible but is it worth it, given we have Components.channels which already solve this?

    The last argument I have is about semantics:

    Given definition 1:

    channels:
      userSignedUp:
          address: user/signedup
          description: ...

    And definition 2:

    channels:
      userSignedUp:
          $ref: "./definition1.yaml/#/channels/userSignedUp"

    When I change definition 1 to:

    channels:
      userSignedUp:
          address: user/loggedout
          description: ...

    Then resolution/dereferencing/bundling will still work
    But the semantics of what userSignedUp is, has changed
    And the channel now represents something completely different

    The current status quo of {channel} being key of Channels Object guarantees that things fail fast if unique {channel} identifier changes, because if it changes it's probably an important change.

  14. char0n commented on Feb 10, 2022

    @char0n
    Member

    Hi guys,

    I was thinking about this some more during the night, and looking at this change through the lens of different persona - as a tooling author (not definition writer) I actually like this change. This changes makes {channel} part of Channel Item Object which makes Channel Item Object self-contained. Currently when Channels Object is parsed into individual Channel Item Object elements, I have to attach to the {channel} (key under which the object is defined, which is very important information) as metadata to the particular Channel Item Object. With this change, maintaining the metadata will no longer be necessary.

    And I want to thank you for giving me the opportunity to voice my opinions here (through two different personas - definitions author and tooling author) and sorry for hijacking this discussion a bit.

  15. 41 remaining items

  16. github-actions commented on Dec 31, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  17. fmvilas commented on Jan 10, 2023

    @fmvilas
    Contributor

    Getting there dear bot. Be patient.

  18. jonaslagoni commented on Mar 9, 2023

    @jonaslagoni
    Member

    This is already done 🙂

  19. github-actions commented on Jul 8, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  20. smoya commented on Jul 11, 2023

    @smoya
    MemberAuthor

    But please bot do not close it yet until v3 is out 🙏

  21. github-actions commented on Nov 10, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    💭 Strawman (RFC 0)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions