Skip to content

Commit

Permalink
feat: support mqtts protocol (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
  • Loading branch information
wandertaker and derberg authored Nov 8, 2022
1 parent 7c47b72 commit 35305fc
Show file tree
Hide file tree
Showing 8 changed files with 629 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Property name | Reason | Fallback | Default
## Supported protocols

* [AMQP](https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol)
* [MQTT](https://en.wikipedia.org/wiki/MQTT)
* [MQTT and MQTTS](https://en.wikipedia.org/wiki/MQTT)
* [Kafka](https://en.wikipedia.org/wiki/Apache_Kafka)
* [WebSocket](https://en.wikipedia.org/wiki/WebSocket)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"supportedProtocols": [
"amqp",
"mqtt",
"mqtts",
"kafka",
"kafka-secure",
"ws"
Expand Down
4 changes: 2 additions & 2 deletions template/config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ default:
durable: true
autoDelete: true
{%- endif %}
{%- if asyncapi.server(params.server).protocol() === "mqtt" %}
{%- if asyncapi.server(params.server).protocol() === "mqtt" or asyncapi.server(params.server).protocol() === "mqtts"%}
mqtt:
url: mqtt://{{ asyncapi.server(params.server).url() | replaceServerVariablesWithValues(asyncapi.server(params.server).variables()) | stripProtocol }}
url: {{ asyncapi.server(params.server).protocol() }}://{{ asyncapi.server(params.server).url() | replaceServerVariablesWithValues(asyncapi.server(params.server).variables()) | stripProtocol }}
topics: {{ asyncapi | channelNamesWithPublish | toMqttTopic | dump | safe }}
qos:
protocol: mqtt
Expand Down
2 changes: 1 addition & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hermesjs": "2.x",
"hermesjs-router": "1.x",
"asyncapi-validator": "3.0.0",
{% if asyncapi.server(params.server).protocol() === 'mqtt' -%}
{% if asyncapi.server(params.server).protocol() === 'mqtt' or asyncapi.server(params.server).protocol() === 'mqtts' -%}
"hermesjs-mqtt": "2.x",
{%- endif -%}
{% if asyncapi.server(params.server).protocol() === 'kafka' or asyncapi.server(params.server).protocol() === 'kafka-secure' -%}
Expand Down
3 changes: 3 additions & 0 deletions template/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const logger = require('./middlewares/logger');
const errorLogger = require('./middlewares/error-logger');
const config = require('../lib/config');
{%- set protocol = asyncapi.server(params.server).protocol() %}
{%- if protocol === 'mqtts' %}
{%- set protocol = 'mqtt' %}
{%- endif %}
const serverConfig = {{ protocol | getConfig }};
const {{ protocol | getProtocol | capitalize }}Adapter = require('hermesjs-{{ protocol | getProtocol }}');
{%- for channelName, channel in asyncapi.channels() %}
Expand Down
Loading

0 comments on commit 35305fc

Please sign in to comment.