Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate functions for sending messages #226

Open
derberg opened this issue Sep 25, 2023 · 11 comments
Open

generate functions for sending messages #226

derberg opened this issue Sep 25, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@derberg
Copy link
Member

derberg commented Sep 25, 2023

After we merge #220 the last bad user experience is 👇🏼

    client.app.send(
        { command: "off" },
        {},
        "smartylighting/streetlights/1/0/action/12/turn/on"
    );

we should generate

function turnOn(message){
    app.send(
        message,
        {},
        "smartylighting/streetlights/1/0/action/12/turn/on"
    );
}

so later user can just do:

turnOn({ command: "off" })
@PUNEET-EMM
Copy link

Hello @derberg , i am new to asyncapi i want to work on this can you tell me more about it..

Copy link
Member Author

derberg commented Oct 2, 2023

hey, thanks, but it is already in progress in #220 PR

@PUNEET-EMM
Copy link

Okay , is their any other issue available ?? for new comer ...

@derberg
Copy link
Member Author

derberg commented Oct 3, 2023

@PUNEET-EMM maybe have a look at https://www.asyncapi.com/community/dashboard

@kaushik-rishi
Copy link
Collaborator

@PUNEET-EMM #220 Has been merged, would you like to work on this issue ?

@derberg I hope we still need this.

Copy link
Member Author

derberg commented May 8, 2024

yeah definitely, as for now to send a message somebody has to use client app api directly for sending, and remember topics names, instead of using a generated send functions, like we have for receiving

@ibishal
Copy link

ibishal commented Jun 20, 2024

Hey @derberg i want to solve this , but i need a little bit more clarity on the issue

Copy link
Member Author

derberg commented Jun 24, 2024

sure, what do you need

me and @kaushik-rishi are here to help

@ibishal
Copy link

ibishal commented Jun 24, 2024

can you elaborate some more details on the issue ?
cc @derberg @kaushik-rishi

@derberg
Copy link
Member Author

derberg commented Jun 25, 2024

it's hard without specific question

you need to get this template, generate code using readme instruction and play with https://github.com/asyncapi/nodejs-template/blob/master/test/example/script.js example script.

you can see that in the example script, available generated client have helpers like client.registerReceiveLightMeasurementMiddleware. They are generated basing on AsyncAPI document content (examine the AsyncAPI document referred in readme, see what names are there and how them map to generated code). So it is super easy to use such a client to subscribe to topic, and provide a callback that will react to incoming messages.

Problem is with sending, to send a message you have to manually write code like

client.app.send(
    { command: 'off' },
    {},
    'smartylighting/streetlights/1/0/action/12/turn/on'
  );

as you can see, the topic address is hardcoded, and person that writes this code, need to look into docs, and make sure they use proper topic. Better would be if client would already give you access to turnOn function that accepts a message payload as argument. And such function name could be generated from the operation id that in in AsyncAPI document -> https://github.com/asyncapi/nodejs-template/blob/master/test/mocks/mqtt/asyncapi-v3.yml#L111C3-L111C9

@kaushik-rishi
Copy link
Collaborator

@derberg fyi, i have connected with @ibishal on slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants