Skip to content

Commit

Permalink
Fix securityProtocol sasl config in consummer
Browse files Browse the repository at this point in the history
  • Loading branch information
gajosu committed Jun 3, 2022
1 parent 0a38103 commit 6ad4f25
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Consumers/ConsumerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function build(): Consumer
$config = new Config(
broker: $this->brokers,
topics: $this->topics,
securityProtocol: $this->securityProtocol,
securityProtocol: $this->getSecurityProtocol(),
commit: $this->commit,
groupId: $this->groupId,
consumer: new CallableConsumer($this->handler, $this->middlewares),
Expand Down Expand Up @@ -395,6 +395,18 @@ private function validateTopic(mixed $topic)
}
}

/**
* Get security protocol depending if sasl is been set.
*
* @return string
*/
private function getSecurityProtocol(): string
{
return $this->saslConfig !== null
? $this->saslConfig->getSecurityProtocol()
: $this->securityProtocol;
}

/**
* Returns batch config if batching is enabled
* if batching is disabled then null config returned
Expand Down
21 changes: 21 additions & 0 deletions tests/Consumers/ConsumerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@ public function testItCanSetSecurityProtocol()
$this->assertEquals('security', $securityProtocol);
}

public function testItCanSetSecurityProtocolViaSaslConfig()
{
$consumer = ConsumerBuilder::create('broker', ['foo'], 'group')
->withSasl(
$sasl = new Sasl(
'username',
'password',
'mechanisms',
'protocol'
)
);

$consummerBuilt = $consumer->build();
$this->assertInstanceOf(Consumer::class, $consummerBuilt);

$consumerConfig = $this->getPropertyWithReflection('config', $consummerBuilt);
$securityProtocol = $this->getPropertyWithReflection('securityProtocol', $consumerConfig);

$this->assertEquals('protocol', $securityProtocol);
}

public function testItCanSetAutoCommit()
{
$consumer = ConsumerBuilder::create('broker')->withAutoCommit();
Expand Down

0 comments on commit 6ad4f25

Please sign in to comment.