From f319c000d7ed2b9ba3bc8784f739032e7e701e96 Mon Sep 17 00:00:00 2001 From: Vaishnavi <41518119+VaishnaviNandakumar@users.noreply.github.com> Date: Thu, 25 May 2023 01:24:55 +0530 Subject: [PATCH] feat: added mqttClientId parameter with a defualt value (#295) * Added mqttClientId parameter with a defualt value * Implemented request changes --------- Co-authored-by: Vaishnavi Nandakumar , Semen --- README.md | 25 +++++++++++---------- package.json | 4 ++++ template/src/main/resources/application.yml | 11 ++++++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index eec0e1f01..9d8451955 100644 --- a/README.md +++ b/README.md @@ -45,18 +45,19 @@ In order for the generator to know what names to use for some parameters it's ne #### Supported parameters -|Name|Description|Required|Default| -|---|---|---|---| -|disableEqualsHashCode|Disable generation of equals and hashCode methods for model classes.|No|`false`| -|inverseOperations|Generate an application that will publish messages to `publish` operation of channels and read messages from `subscribe` operation of channels. Literally this flag will simply swap `publish` and `subscribe` operations in the channels.
This flag will be useful when you want to generate a code of mock for your main application. Be aware, generation could be incomplete and manual changes will be required e.g. if bindings are defined only for case of main application.|No|`false`| -|javaPackage|The Java package of the generated classes. Alternatively you can set the specification extension `info.x-java-package`. If both extension and parameter are used, parameter has more priority.|No|`com.asyncapi`| -|listenerPollTimeout|Only for Kafka. Timeout in ms to use when polling the consumer.|No|`3000`| -|listenerConcurrency|Only for Kafka. Number of threads to run in the listener containers.|No|`3`| -|addTypeInfoHeader|Only for Kafka. Add type information to message header.|No|`true`| -|connectionTimeout|Only for MQTT. This value, measured in seconds, defines the maximum time interval the client will wait for the network connection to the MQTT server to be established. The default timeout is 30 seconds. A value of 0 disables timeout processing meaning the client will wait until the network connection is made successfully or fails.|No|`30`| -|disconnectionTimeout|Only for MQTT. The completion timeout in milliseconds when disconnecting. The default disconnect completion timeout is 5000 milliseconds.|No|`5000`| -|completionTimeout|Only for MQTT. The completion timeout in milliseconds for operations. The default completion timeout is 30000 milliseconds.|No|`30000`| -|asyncapiFileDir| Path where original AsyncAPI file will be stored.|No|`src/main/resources/api/`| +|Name|Description|Required| Default | +|---|---|---|----------------------| +|disableEqualsHashCode|Disable generation of equals and hashCode methods for model classes.|No| `false` | +|inverseOperations|Generate an application that will publish messages to `publish` operation of channels and read messages from `subscribe` operation of channels. Literally this flag will simply swap `publish` and `subscribe` operations in the channels.
This flag will be useful when you want to generate a code of mock for your main application. Be aware, generation could be incomplete and manual changes will be required e.g. if bindings are defined only for case of main application.|No| `false` | +|javaPackage|The Java package of the generated classes. Alternatively you can set the specification extension `info.x-java-package`. If both extension and parameter are used, parameter has more priority.|No| `com.asyncapi` | +|listenerPollTimeout|Only for Kafka. Timeout in ms to use when polling the consumer.|No| `3000` | +|listenerConcurrency|Only for Kafka. Number of threads to run in the listener containers.|No| `3` | +|addTypeInfoHeader|Only for Kafka. Add type information to message header.|No| `true` | +|connectionTimeout|Only for MQTT. This value, measured in seconds, defines the maximum time interval the client will wait for the network connection to the MQTT server to be established. The default timeout is 30 seconds. A value of 0 disables timeout processing meaning the client will wait until the network connection is made successfully or fails.|No| `30` | +|disconnectionTimeout|Only for MQTT. The completion timeout in milliseconds when disconnecting. The default disconnect completion timeout is 5000 milliseconds.|No| `5000` | +|completionTimeout|Only for MQTT. The completion timeout in milliseconds for operations. The default completion timeout is 30000 milliseconds.|No| `30000` | +|mqttClientId| Only for MQTT. Provides the client identifier for the MQTT server. This parameter overrides the value of the clientId if it's set in the AsyncAPI file.If both aren't provided, a default value is set.|No| | +|asyncapiFileDir| Path where original AsyncAPI file will be stored.|No| `src/main/resources/api/` | #### Examples The shortest possible syntax: diff --git a/package.json b/package.json index 9530a1656..26a252ffe 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,10 @@ "default": 30000, "required": false }, + "mqttClientId": { + "description": "Only for MQTT. Provides the client identifier for the MQTT server. This parameter overrides the value of the clientId if it's set in the AsyncAPI file.", + "required": false + }, "asyncapiFileDir": { "description": "Parameter of @asyncapi/generator-hooks#createAsyncapiFile, allows to specify where original AsyncAPI file will be stored.", "default": "src/main/resources/api/", diff --git a/template/src/main/resources/application.yml b/template/src/main/resources/application.yml index a1cbf536e..148633a24 100644 --- a/template/src/main/resources/application.yml +++ b/template/src/main/resources/application.yml @@ -8,6 +8,7 @@ {%- set hasSubscribe = true -%} {%- endif -%} {%- endfor -%} + {%- for serverName, server in asyncapi.servers() %}{% if server.protocol() == 'amqp' %} amqp: broker: {% for line in server.description() | splitByLines %} @@ -29,6 +30,7 @@ amqp: {% endif %} {% endfor %} {% endif %} + {% if server.protocol() == 'mqtt' %} mqtt: broker: {% for line in server.description() | splitByLines %} @@ -36,7 +38,13 @@ mqtt: address: {% if server.variable('port') %}{{server.url() | replace('{port}', server.variable('port').defaultValue())}}{% else %}{{server.url()}}{% endif %} username: password: - {% if server.binding('mqtt') and server.binding('mqtt').clientId %}clientId: {{server.binding('mqtt').clientId}}{% endif %} + {% if params.mqttClientId %} + clientId : {{ params.mqttClientId }} + {% elif server.binding('mqtt') and server.binding('mqtt').clientId %} + clientId: {{ server.binding('mqtt').clientId }} + {% else %} + clientId: default + {% endif %} {% if server.binding('mqtt') and server.binding('mqtt').cleanSession | isDefined %}cleanSession: {{server.binding('mqtt').cleanSession}}{% endif %} {% if server.binding('mqtt') and server.binding('mqtt').lastWill %}lastWill: topic: {{server.binding('mqtt').lastWill.topic}} @@ -56,6 +64,7 @@ mqtt: {{channel.subscribe().id() | camelCase}}: {{channelName}} {% endif %}{% endfor %} {% endif %}{% endfor %} + {%- if asyncapi | isProtocol('kafka') %} spring: kafka: {% for serverName, server in asyncapi.servers() %}