You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/message-format.md
+26-15Lines changed: 26 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,11 +73,11 @@ But this can be easily changed by creating your own implementation of the Taskiq
73
73
74
74
Serializers define the format of the message but not the structure. For example, if you want to use msgpack or ORJson to serialize your message, you should update the serializer of your broker.
75
75
76
-
Be default, Taskiq uses JSON serializer. But we also have some implementations of other serializers:
76
+
By default, Taskiq uses JSON serializer. But we also have some implementations of other serializers:
77
77
78
78
* ORJSONSerializer - faster [JSON implementation](https://pypi.org/project/orjson/). Also, it supports datetime and UUID serialization.
79
79
* MSGPackSerializer - [MsgPack](https://pypi.org/project/msgpack/) format serializer. It might be useful to send less data over the network.
80
-
* CBORSerializer - [CBOR](https://pypi.org/project/cbor2/) format serializer. It is also has a smaller size than JSON.
80
+
* CBORSerializer - [CBOR](https://pypi.org/project/cbor2/) format serializer. It also has a smaller size than JSON.
81
81
82
82
To define your own serializer, you have to subclass the TaskiqSerializer class and implement `dumpb` and `loadb` methods. You can take a look at the existing implementations from the `taskiq.serializers` module.
83
83
@@ -91,23 +91,37 @@ To install taskiq with libraries for non-JSON serializers, you should install ta
91
91
pip install "taskiq[orjson]"
92
92
```
93
93
94
+
@tab msgpack
95
+
96
+
```bash
97
+
pip install "taskiq[msgpack]"
98
+
```
99
+
100
+
@tab cbor
101
+
102
+
```bash
103
+
pip install "taskiq[cbor]"
104
+
```
105
+
106
+
:::
107
+
108
+
109
+
After that, you can use your preferred serializer in your project like this:
Formatters define the format of the message. It might be useful if you'd like to send a task to a celery worker for a different project. You can do it in seriazier as well, but formatters give you correct type hints.
146
+
Formatters define the format of the message. It might be useful if you'd like to send a task to a celery worker for a different project. You can do it in serializer as well, but formatters give you correct type hints.
136
147
137
148
By default we use a formatter that dumps the message to dict and serializes it using serializer. But you can define your own formatter to send a message in any format you want. To define a new formatter, you have to subclass the TaskiqFormatter class and implement `dumps` and `loads` methods.
138
149
As an example, you can take a look at the `JSONFormatter` from `taskiq.formatters` implementation.
0 commit comments