@jsh/mqtt
Since v8.0.52Client
MQTT 클라이언트입니다.
사용 예시
생성
| Constructor | 설명 |
|---|
| new Client(options) | 옵션과 함께 MQTT 클라이언트를 생성합니다. |
옵션
| 옵션 | 타입 | 기본값 | 설명 |
|---|
| serverUrls | String[] | | 브로커 주소 목록 |
| keepAlive | Number | 10 | Keep Alive 초 |
| cleanStart | Boolean | true | 클린 세션 여부 |
| username | String | | 사용자 이름 |
| password | String | | 비밀번호 |
| clientID | String | 랜덤 ID | 클라이언트 ID |
| debug | Boolean | false | 디버그 로그 출력 여부 |
| sessionExpiryInterval | Number | 60 | 세션 만료 시간(초) |
| connectRetryDelay | Number | 10 | 재접속 지연(초) |
| connectTimeout | Number | 10 | 접속 타임아웃(초) |
| packetTimeout | Number | 5 | 패킷 타임아웃(초) |
| queue | String | memory | 메시지 큐 저장 방식 |
connect()
사용 형식
매개변수
| Property | Type | 설명 |
|---|
| timeout | Number | 접속 타임아웃(밀리초) |
반환값
없음.
disconnect()
사용 형식
매개변수
| Property | Type | 설명 |
|---|
| waitForEmptyQueue | Boolean | 큐가 빌 때까지 기다릴지 여부 |
| timeout | Number | 종료 대기 타임아웃(밀리초) |
반환값
없음.
subscribe()
사용 형식
매개변수
opts Object SubscriptionOption
SubscriptionOption
| Property | Type | 설명 |
|---|
| subscriptions | Object[] | Subscription 배열 |
| properties | Object | Properties 객체 |
Subscription
| Property | Type | 설명 |
|---|
| topic | String | 구독할 토픽 |
| qos | Number | 0, 1, 2 |
| retainHandling | Number | Retain 처리 방식 |
| noLocal | Boolean | 로컬 발행 메시지 수신 차단 |
| retainAsPublished | Boolean | retain 플래그 유지 여부 |
Properties
| Property | Type | 설명 |
|---|
| user | Object | 사용자 정의 프로퍼티 |
반환값
없음.
사용 예시
unsubscribe()
사용 형식
매개변수
opts Object UnsubscribeOption
UnsubscribeOption
| Property | Type | 설명 |
|---|
| topics | String[] | 해지할 토픽 목록 |
| properties | Object | Properties 객체 |
Properties
| Property | Type | 설명 |
|---|
| user | Object | 사용자 정의 프로퍼티 |
반환값
없음.
사용 예시
publish()
사용 형식
매개변수
opts Object PublishOptionspayload String 또는 Number
PublishOptions
| Property | Type | 설명 |
|---|
| topic | String | 발행할 토픽 |
| qos | Number | 0, 1, 2 |
| packetID | String | 패킷 ID |
| retain | Boolean | retain 플래그 |
| properties | Object | MQTT v5 프로퍼티 |
반환값
| Property | Type | Description |
|---|
| reasonCode | Number | |
| properties | Object | |
사용 예시
onMessage callback
Callback function that receives a message.
사용 형식
Message
| Property | Type | Description |
|---|
| packetID | Number | |
| topic | String | |
| qos | Number | 0, 1, 2 |
| retain | Boolean | |
| payload | Object | Payload |
| properties | Object | Properties |
Payload
msg.payload.bytes()msg.payload.string()
Properties
| Property | Type | Description |
|---|
| correlationData | byte[] | |
| contentType | String | |
| responseTopic | String | |
| payloadFormat | Number | or undefined |
| messageExpiry | Number | or undefined |
| subscriptionIdentifier | Number | or undefined |
| topicAlias | Number | or undefined |
| user | Object | user properties |
onConnect callback
On connect callback.
사용 형식
매개변수
| Property | Type | Description |
|---|
| sessionPresent | Boolean | |
| reasonCode | Number | |
| properties | Object | Properties |
Properties
| Property | Type | Description |
|---|
| reasonString | String | |
| reasonInfo | String | |
| assignedClientID | String | |
| authMethod | String | |
| serverKeepAlive | Number | or undefined |
| sessionExpiryInterval | Number | or undefined |
| user | Object | |
반환값
없음.
onConnectError callback
On connect error callback.
사용 형식
매개변수
반환값
없음.
onDisconnect callback
On disconnect callback
사용 형식
매개변수
반환값
없음.
onClientError callback
On client error callback
사용 형식
매개변수
반환값
없음.