Skip to content

Commit

Permalink
fix: sending messages in mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 committed Mar 12, 2024
1 parent a5e98de commit 1bd5df0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/adapters/mqtt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,11 @@ class MqttAdapter extends Adapter {

_send(message: GleeMessage): Promise<void> {
return new Promise((resolve, reject) => {
const binding = this.parsedAsyncAPI
.channels()
.get(message.channel)
.bindings()
.get('mqtt')
?.value()
const channel = this.parsedAsyncAPI.channels().get(message.channel)
const address = channel.address()
const binding = channel.bindings().get('mqtt')?.value()
this.client.publish(
message.channel,
address,
message.payload,
{
qos: binding?.qos ? binding.qos : 2,
Expand Down
21 changes: 20 additions & 1 deletion src/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,26 @@ export async function trigger({
localServerProtocols.includes(serverProtocol) &&
!isRemoteServer(parsedAsyncAPI, msg.server)
const channelName = msg.channel || message.channel
const operations = parsedAsyncAPI.channels().get(channelName).operations().filterBySend()
const channel = parsedAsyncAPI.channels().get(channelName)

if (!channel) {
const warnMessage = `Failed to send: "${channelName}" channel not found. please make sure you have a channel named: "${channelName}" in your AsyncAPI file.`
logWarningMessage(warnMessage, {
highlightedWords: [channelName],
})
return
}

const operations = channel.operations().filterBySend()

if (operations.length === 0) {
const warnMessage = `Failed to send: No 'send' operation found for channel "${channelName}".`
logWarningMessage(warnMessage, {
highlightedWords: [channelName],
})
return
}

operations.forEach(operation => {
app.send(
new GleeMessage({
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"compilerOptions": {
"skipLibCheck": true,
"outDir": "./dist",
"allowJs": false,
"target": "es6",
"esModuleInterop": true,
"moduleResolution": "nodenext",
"module": "es2020"
"module": "NodeNext"
},
"include": [
"./src/**/*"
Expand Down

0 comments on commit 1bd5df0

Please sign in to comment.