Connecting to microservice (MQTT)
See original GitHub issueI’m submitting a…
[ ] Regression
[X] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Endless connecting without exception or success to microservice.
Expected behavior
Exception or successful connection.
Minimal reproduction of the problem with instructions
main.ts
import { INestMicroservice } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { Transport } from "@nestjs/microservices";
import { AppModule } from "./app.module";
async function bootstrap(): Promise<void> {
const app: INestMicroservice = await NestFactory.createMicroservice(
AppModule,
{
transport: Transport.MQTT,
options: {
host: "broker.hivemq.com",
port: 1883
}
}
);
await app.listenAsync();
}
bootstrap();
app.module.ts
import { Module } from "@nestjs/common";
import { AppService } from "./app.service";
@Module({
providers: [AppService]
})
export class AppModule {}
app.service.ts
import { Injectable, Logger } from "@nestjs/common";
import { Client, ClientProxy, Transport } from "@nestjs/microservices";
import { Observable } from "rxjs";
@Injectable()
export class AppService {
@Client({ transport: Transport.MQTT })
public client: ClientProxy;
public async onModuleInit(): Promise<void> {
Logger.log("Connecting");
await this.client.connect();
Logger.log("Connected");
}
public sendMessage(): Observable<number> {
const pattern: {} = { cmd: "sum" };
const data: number[] = [5, 6];
return this.client.send<number>(pattern, data);
}
}
What is the motivation / use case for changing the behavior?
Environment
Nest version: 5.3.0
For Tooling issues:
- Node version: 10.9.0
- Platform: Mac OS
Others:
You can use the broker.hivemq.com which is publicly accessible and actually works.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
MQTT - Microservices - A progressive Node.js framework
This protocol provides a scalable and cost-efficient way to connect devices using a publish/subscribe model. A communication system built on MQTT consists ...
Read more >Event-based-microservices: MQTT with Broker OR HTTP with ...
Both is definitely a possibility! Choose a broker that allows you to easily mix-and-match between HTTP (synchronous) communication, ...
Read more >Event Driven Microservices Architecture for IoT Solutions ...
In this article, I'll discuss an event-driven microservices architecture approach for IoT using MQTT with HiveMQ MQTT Broker as the central ...
Read more >REST and MQTT: Yin and Yang of Micro-Service APIs
This establishes the baseline state. All the services will simultaneously connect to a message broker.
Read more >Getting Started with Node.js and MQTT - Blog - RisingStack
Next up, we'll add some code to connect to the broker. Once connected we'll create a topic (channel) that will be used to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Exactly.
As I mentioned, this interface is an external one, it comes directly from MQTT library https://github.com/mqttjs/MQTT.js/blob/master/types/lib/client-options.d.ts. We simply pass down all
options
properties to theMqttClient
instance.Yes
MQTT transport works properly as well. Not sure it cannot connect only to
broker.hivemq.com