Skip to content

Commit eb29304

Browse files
committed
docs: separate code example from installation comand and fix typos
1 parent 8667a3e commit eb29304

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

docs/guide/message-format.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ But this can be easily changed by creating your own implementation of the Taskiq
7373

7474
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.
7575

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:
7777

7878
* ORJSONSerializer - faster [JSON implementation](https://pypi.org/project/orjson/). Also, it supports datetime and UUID serialization.
7979
* 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.
8181

8282
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.
8383

@@ -91,23 +91,37 @@ To install taskiq with libraries for non-JSON serializers, you should install ta
9191
pip install "taskiq[orjson]"
9292
```
9393

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:
110+
111+
::: tabs
112+
113+
@tab orjson
114+
94115
```python
95-
# broker.py
96116
from taskiq import InMemoryBroker
97117
from taskiq.serializers import ORJSONSerializer
98118

99119
broker = InMemoryBroker().with_serializer(ORJSONSerializer())
100120
```
101121

102-
103122
@tab msgpack
104123

105-
```bash
106-
pip install "taskiq[msgpack]"
107-
```
108-
109124
```python
110-
# broker.py
111125
from taskiq import InMemoryBroker
112126
from taskiq.serializers import MSGPackSerializer
113127

@@ -116,12 +130,7 @@ broker = InMemoryBroker().with_serializer(MSGPackSerializer())
116130

117131
@tab cbor
118132

119-
```bash
120-
pip install "taskiq[cbor]"
121-
```
122-
123133
```python
124-
# broker.py
125134
from taskiq import InMemoryBroker
126135
from taskiq.serializers import CBORSerializer
127136

@@ -130,9 +139,11 @@ broker = InMemoryBroker().with_serializer(CBORSerializer())
130139

131140
:::
132141

142+
143+
133144
### Formatters
134145

135-
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.
136147

137148
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.
138149
As an example, you can take a look at the `JSONFormatter` from `taskiq.formatters` implementation.

0 commit comments

Comments
 (0)