-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87e834b
commit 1e01a8d
Showing
7 changed files
with
103 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
To publish message to the broker, you need to serialize your data to byte array `UInt8List` | ||
To publish message to the broker, you need can pass your object instance, it will try to loop all message adapters to encode the instance into Uint8List, the first one that is able to encode, will be used. You can also pass an optional, encoder function that will pass your instance as `dynamic` which you can use to call your own method to encode to `Uint8List` | ||
|
||
```dart | ||
// Example of Custom TestData class | ||
Uint8List testDataEncoder(TestData testData) => testData.toBytes(); | ||
``` | ||
|
||
Next, you need to initalize `CourierMessage` instance passing the `bytes`, `topic` string, and `qos` like so. | ||
You need to initalize `CourierMessage` instance passing the `payload`, `topic` string, and `qos` like so. Finally, you need to invoke `publishCourierMessage` on `CourierClient` passing the message. | ||
|
||
```dart | ||
final message = CourierMessage( | ||
bytes: testDataEncoder(TestData("Hello World")), | ||
topic: "/chat/user1", | ||
qos: QoS.one | ||
) | ||
``` | ||
/// This used JSONMessageAdapter which use dart jsonEncode to invoke toJson on object implicitly | ||
courierClient.publishCourierMessage(CourierMessage( | ||
payload: Person(name: textMessage), | ||
topic: "person/6b57d4e5-0fce-4917-b343-c8a1c77405e5/update", | ||
qos: QoS.one)); | ||
Finally, you need to invoke `publishCourierMessage` on `CourierClient` passing the message. | ||
|
||
```dart | ||
courierClient.publishCourierMessage(mesage); | ||
/// For this TestData without toJson method, you can provide your own encode to convert to Uint8List/bytes | ||
courierClient.publishCourierMessage( | ||
CourierMessage( | ||
payload: testData, | ||
topic: "orders/6b57d4e5-0fce-4917-b343-c8a1c77405e5/update", | ||
qos: QoS.one), | ||
encoder: (testData) => testData.toBytes()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters