feat(M06-A): 建立MQTT连接与Broker基础
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
FetchThirdPartyTransport, parseThirdPartyCredentials, ThirdPartyClient
|
||||
} from './third-party/third-party-client.js';
|
||||
import { ThirdPartyService } from './third-party/third-party-service.js';
|
||||
import { MqttService } from './mqtt/mqtt-service.js';
|
||||
|
||||
const config = loadConfig();
|
||||
const pool = createMySqlPool(config);
|
||||
@@ -36,8 +37,10 @@ const paymentRepository = new PaymentRepository(pool);
|
||||
const wechatCredentials = parseWechatPayCredentials(config.payment.wechatCredentialsJson);
|
||||
const wechatPayClient = new WechatPayClient(new FetchWechatPayTransport());
|
||||
const thirdPartyCredentials = parseThirdPartyCredentials(config.thirdParty.credentialsJson);
|
||||
const mqtt = new MqttService(config.mqtt);
|
||||
const app = await buildApp({
|
||||
config,
|
||||
mqtt,
|
||||
platformConfigRepository: new PlatformConfigRepository(pool),
|
||||
auth: {
|
||||
repository: authRepository,
|
||||
@@ -133,10 +136,12 @@ const app = await buildApp({
|
||||
}
|
||||
});
|
||||
app.addHook('onClose', async () => {
|
||||
await mqtt.stop();
|
||||
await closeMySqlPool(pool);
|
||||
});
|
||||
|
||||
try {
|
||||
mqtt.start();
|
||||
await app.listen({ host: config.host, port: config.port });
|
||||
} catch (error) {
|
||||
app.log.error(error);
|
||||
|
||||
Reference in New Issue
Block a user