Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom header option for consumers #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
</exclude>
</whitelist>
</filter>
</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion src/Messenger/KafkaReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function get(): iterable

$envelope = $this->serializer->decode([
'body' => $message->payload,
'headers' => $message->headers,
'headers' => array_merge($this->properties->getHeaders(), $message->headers ?? []),
'key' => $message->key,
'offset' => $message->offset,
'timestamp' => $message->timestamp,
Expand Down
12 changes: 11 additions & 1 deletion src/Messenger/KafkaReceiverProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ final class KafkaReceiverProperties
/** @var bool */
private $commitAsync;

/** @var array */
private $headers;

public function __construct(
KafkaConf $kafkaConf,
string $topicName,
int $receiveTimeoutMs,
bool $commitAsync
bool $commitAsync,
array $headers
) {
$this->kafkaConf = $kafkaConf;
$this->topicName = $topicName;
$this->receiveTimeoutMs = $receiveTimeoutMs;
$this->commitAsync = $commitAsync;
$this->headers = $headers;
}

public function getKafkaConf(): KafkaConf
Expand All @@ -51,4 +56,9 @@ public function isCommitAsync(): bool
{
return $this->commitAsync;
}

public function getHeaders(): array
{
return $this->headers;
}
}
3 changes: 2 additions & 1 deletion src/Messenger/KafkaTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function createTransport(string $dsn, array $options, SerializerInterface
$conf,
$options['topic']['name'],
$options['receiveTimeout'] ?? 10000,
$options['commitAsync'] ?? false
$options['commitAsync'] ?? false,
$options['headers'] ?? []
)
);
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/Messenger/KafkaTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function testConstruct()
new KafkaConf(),
'test',
10000,
false
false,
[]
)
);

Expand Down Expand Up @@ -110,6 +111,9 @@ public function testGet()
'type' => TestMessage::class,
'Content-Type' => 'application/json',
],
'key' => null,
'offset' => 0,
'timestamp' => 1586861356,
])
->willReturn(new Envelope(new TestMessage()));

Expand All @@ -127,7 +131,8 @@ public function testGet()
new KafkaConf(),
'test',
10000,
false
false,
[]
)
);

Expand Down