Skip to content

Commit f1601fd

Browse files
committed
[rdkafka] add docs
1 parent 00b3bc5 commit f1601fd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/transport/kafka.md

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The transport uses [Kafka](https://kafka.apache.org/) streaming platform as a MQ
77
* [Send message to topic](#send-message-to-topic)
88
* [Send message to queue](#send-message-to-queue)
99
* [Consume message](#consume-message)
10+
* [Serialize message](#serialize-message)
1011

1112
## Installation
1213

@@ -88,4 +89,27 @@ $consumer->acknowledge($message);
8889
// $consumer->reject($message);
8990
```
9091

92+
## Serialize message
93+
94+
By default the transport serializes messages to json format but you might want to use another format such as [Apache Avro](https://avro.apache.org/docs/1.2.0/).
95+
For that you have to implement Serializer interface and set it to the context, producer or consumer.
96+
If a serializer set to context it will be injected to all consumers and producers created by the context.
97+
98+
```php
99+
<?php
100+
use Enqueue\RdKafka\Serializer;
101+
use Enqueue\RdKafka\RdKafkaMessage;
102+
103+
class FooSerializer implements Serializer
104+
{
105+
public function toMessage($string) {}
106+
107+
public function toString(RdKafkaMessage $message) {}
108+
}
109+
110+
/** @var \Enqueue\RdKafka\RdKafkaContext $psrContext */
111+
112+
$psrContext->setSerializer(new FooSerializer());
113+
```
114+
91115
[back to index](index.md)

0 commit comments

Comments
 (0)