Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjunges committed Sep 28, 2021
1 parent bd717ee commit c375e10
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

All relevant changes to `mateusjunges/laravel-kafka` will be documented here.

## [2021-09-28 v1.1.0](https://github.com/mateusjunges/laravel-kafka/compare/v1.0.2...v1.1.0)
## [2021-09-28 v1.1.1](https://github.com/mateusjunges/laravel-kafka/compare/v1.1.0...v1.1.1)
### Fixed
- Fixed documentation about message handlers
- Fixed tests to test a message can be consumed using message handlers

## [2021-09-27 v1.1.0](https://github.com/mateusjunges/laravel-kafka/compare/v1.0.2...v1.1.0)
### Added
- Added option to use custom serializers/deserializers with Kafka([#5](https://github.com/mateusjunges/laravel-kafka/pull/5))
- Added default AVRO, Json and Null serializers/deserializers ([#5](https://github.com/mateusjunges/laravel-kafka/pull/5))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ You can use an invokable class or a simple callback. Use the `withHandler` metho
$consumer = \Junges\Kafka\Facades\Kafka::createConsumer('broker');

// Using callback:
$consumer->withHandler(function(\RdKafka\Message $message) {
$consumer->withHandler(function(\Junges\Kafka\Contracts\KafkaConsumerMessage $message) {
// Handle your message here
});
```
Expand All @@ -293,7 +293,7 @@ Or, using a invokable class:
```php
class Handler
{
public function __invoke(\RdKafka\Message $message){
public function __invoke(\Junges\Kafka\Contracts\KafkaConsumerMessage $message){
// Handle your message here
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Consumers/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use Junges\Kafka\Config\Config;
use Junges\Kafka\Consumers\Consumer;
use Junges\Kafka\Exceptions\KafkaConsumerException;
use Junges\Kafka\Facades\Kafka;
use Junges\Kafka\Message\ConsumedMessage;
use Junges\Kafka\Message\Deserializers\JsonDeserializer;
use Junges\Kafka\Tests\Fakes\FakeConsumer;
use Junges\Kafka\Tests\Fakes\FakeHandler;
use Junges\Kafka\Tests\LaravelKafkaTestCase;
use RdKafka\Message;
Expand Down Expand Up @@ -46,6 +48,29 @@ public function testItConsumesAMessageSuccessfullyAndCommit()
$this->assertInstanceOf(ConsumedMessage::class, $fakeHandler->lastMessage());
}

public function testItCanConsumeMessages()
{
$message = new Message();
$message->err = 0;
$message->key = 'key';
$message->topic_name = 'test';
$message->payload = '{"body": "message payload"}';

$this->mockConsumerWithMessage($message);

$this->mockProducer();

$consumer = Kafka::createConsumer('broker', ['test'])
->withHandler($fakeConsumer = new FakeConsumer())
->withAutoCommit()
->withMaxMessages(1)
->build();

$consumer->consume();

$this->assertInstanceOf(ConsumedMessage::class, $fakeConsumer->getMessage());
}

public function testConsumeMessageWithError()
{
$this->mockProducer();
Expand Down
8 changes: 4 additions & 4 deletions tests/Fakes/FakeConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Junges\Kafka\Tests\Fakes;

use RdKafka\Message;
use Junges\Kafka\Contracts\KafkaConsumerMessage;

class FakeConsumer
{
private Message $message;
private KafkaConsumerMessage $message;

public function __invoke(Message $message)
public function __invoke(KafkaConsumerMessage $message)
{
$this->message = $message;
}

public function getMessage(): Message
public function getMessage(): KafkaConsumerMessage
{
return $this->message;
}
Expand Down

0 comments on commit c375e10

Please sign in to comment.