@@ -13,23 +13,19 @@ Create a client and connect to the MQTT broker.
13
13
let client = MQTTClient (
14
14
host : " mqtt.eclipse.org" ,
15
15
port : 1883 ,
16
+ identifier : " My Client" ,
16
17
eventLoopGroupProvider : .createNew
17
18
)
18
- let connect = MQTTConnectInfo (
19
- cleanSession : true ,
20
- keepAliveSeconds : 15 ,
21
- clientIdentifier : identifier
22
- )
23
- try client.connect (info : connect).wait ()
19
+ try client.connect ().wait ()
24
20
```
25
21
26
22
Subscribe to a topic and add a publish listener to report publish messages from the server.
27
23
``` swift
28
24
let subscription = MQTTSubscribeInfo (
29
- qos : . atLeastOnce ,
30
- topicFilter : " my-topics "
25
+ topicFilter : " my-topics " ,
26
+ qos : . atLeastOnce
31
27
)
32
- try client.subscribe (infos : [subscription]).wait ()
28
+ try client.subscribe (to : [subscription]).wait ()
33
29
client.addPublishListener (" My Listener" ) { result in
34
30
switch result {
35
31
case .success (let publish):
@@ -44,13 +40,11 @@ client.addPublishListener("My Listener") { result in
44
40
45
41
Publish to a topic.
46
42
``` swift
47
- let publish = MQTTPublishInfo (
48
- qos : .atLeastOnce ,
49
- retain : false ,
50
- topicName : " my-topics" ,
51
- payload : ByteBufferAllocator ().buffer (string : " This is the Test payload" )
52
- )
53
- try client.publish (info : publish).wait ()
43
+ try client.publish (
44
+ to : " my-topics" ,
45
+ payload : ByteBufferAllocator ().buffer (string : " This is the Test payload" ),
46
+ qos : .atLeastOnce
47
+ ).wait ()
54
48
```
55
49
## TLS
56
50
@@ -68,6 +62,7 @@ let tlsConfiguration: TLSConfiguration? = TLSConfiguration.forClient(
68
62
let client = MQTTClient (
69
63
host : " test.mosquitto.org" ,
70
64
port : 8884 ,
65
+ identifier : " MySSLClient" ,
71
66
eventLoopGroupProvider : .createNew ,
72
67
configuration : .init (useSSL : true , tlsConfiguration : tlsConfiguration),
73
68
)
0 commit comments