Skip to content

Commit 671a7f9

Browse files
authored
Chore/add migration note (#6)
* add migration hint * update readme * update readme version * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan * fix stan
1 parent 5087383 commit 671a7f9

24 files changed

+70
-53
lines changed

MIGRATION.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Migration from messaging-lib to php-kafka-lib
2+
3+
Internally not much has changed, we have mostly gotten rid of,
4+
the general interfaces, since we won't implement support for other
5+
messaging systems than Kafka.
6+
7+
In most cases you can just:
8+
1. `composer remove jobcloud/messaging-lib`
9+
2. `composer require jobcloud/php-kafka-lib ~0.1`
10+
3. Replace namespace `Jobcloud\Messaging\Kafka` with `Jobcloud\Kafka`
11+
4. Replace the following:
12+
- `ConsumerException` with `KafkaConsumerConsumeException`
13+
- `MessageInterface` with `KafkaMessageInterface` or depending on your use case with `KafkaConsumerMessageInterface` and `KafkaProducerMessageInterface`
14+
- `ProducerInterface` with `KafkaProducerInterface`
15+
- `ConsumerInterface` with `KafkaConsumerInterface`
16+
- `ProducerPool` is not supported anymore

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ can help out to understand the internals of this library.
2020
- ext-rdkafka: ^4.0.0
2121

2222
## Installation
23-
```composer require jobcloud/php-kafka-lib "~1.0"```
23+
```composer require jobcloud/php-kafka-lib "~0.1"```
2424

2525
## Usage
2626

@@ -260,4 +260,5 @@ while (true) {
260260
```
261261

262262
## Additional information
263-
Replaces [messaging-lib](https://github.com/jobcloud/messaging-lib)
263+
Replaces [messaging-lib](https://github.com/jobcloud/messaging-lib)
264+
Check [Migration.md](MIGRATION.md) for help to migrate.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"flix-tech/avro-serde-php": "^1.3"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^8.4",
27-
"squizlabs/php_codesniffer": "^3.4.2",
28-
"phpstan/phpstan": "^0.11.12",
29-
"php-mock/php-mock-phpunit": "^2.5",
26+
"phpunit/phpunit": "^9.1",
27+
"squizlabs/php_codesniffer": "^3.5.4",
28+
"phpstan/phpstan": "^0.12.18",
29+
"php-mock/php-mock-phpunit": "^2.6",
3030
"kwn/php-rdkafka-stubs": "^2.0.0",
3131
"rregeer/phpunit-coverage-check": "^0.3.1",
3232
"johnkary/phpunit-speedtrap": "^3.1"

docker/dev/php/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.3-cli-alpine3.10
1+
FROM php:7.3-cli-alpine3.11
22

33
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
44
ENV COMPOSER_ALLOW_SUPERUSER 1

src/Callback/KafkaConsumerRebalanceCallback.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RdKafka\KafkaConsumer as RdKafkaConsumer;
88
use Jobcloud\Kafka\Exception\KafkaRebalanceException;
99
use RdKafka\Exception as RdKafkaException;
10+
use RdKafka\TopicPartition as RdKafkaTopicPartition;
1011

1112
// phpcs:disable
1213
require_once __DIR__ . '/../Exception/KafkaRebalanceException.php'; // @codeCoverageIgnore
@@ -18,7 +19,7 @@ final class KafkaConsumerRebalanceCallback
1819
/**
1920
* @param RdKafkaConsumer $consumer
2021
* @param integer $errorCode
21-
* @param array|null $partitions
22+
* @param array|RdKafkaTopicPartition[]|null $partitions
2223
* @throws KafkaRebalanceException
2324
* @return void
2425
*/

src/Conf/KafkaConfiguration.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class KafkaConfiguration extends RdKafkaConf
1111
{
1212

1313
/**
14-
* @var array
14+
* @var string[]
1515
*/
1616
protected $brokers;
1717

1818
/**
19-
* @var array
19+
* @var array|TopicSubscription[]
2020
*/
2121
protected $topicSubscriptions;
2222

@@ -26,10 +26,10 @@ class KafkaConfiguration extends RdKafkaConf
2626
protected $timeout;
2727

2828
/**
29-
* @param array $brokers
30-
* @param array $topicSubscriptions
29+
* @param string[] $brokers
30+
* @param array|TopicSubscription[] $topicSubscriptions
3131
* @param integer $timeout
32-
* @param array $config
32+
* @param mixed[] $config
3333
*/
3434
public function __construct(array $brokers, array $topicSubscriptions, int $timeout, array $config = [])
3535
{
@@ -43,7 +43,7 @@ public function __construct(array $brokers, array $topicSubscriptions, int $time
4343
}
4444

4545
/**
46-
* @return array
46+
* @return string[]
4747
*/
4848
public function getBrokers(): array
4949
{
@@ -67,15 +67,15 @@ public function getTimeout(): int
6767
}
6868

6969
/**
70-
* @return array
70+
* @return string[]
7171
*/
7272
public function getConfiguration(): array
7373
{
7474
return $this->dump();
7575
}
7676

7777
/**
78-
* @param array $config
78+
* @param mixed[] $config
7979
* @return void
8080
*/
8181
protected function initializeConfig(array $config = []): void

src/Consumer/AbstractKafkaConsumer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Jobcloud\Kafka\Exception\KafkaConsumerConsumeException;
1313
use Jobcloud\Kafka\Message\KafkaConsumerMessage;
1414
use RdKafka\Consumer as RdKafkaLowLevelConsumer;
15-
use RdKafka\ConsumerTopic as RdKafkaConsumerTopic;
1615
use RdKafka\Exception as RdKafkaException;
1716
use RdKafka\KafkaConsumer as RdKafkaHighLevelConsumer;
1817
use RdKafka\Metadata\Topic as RdKafkaMetadataTopic;
@@ -71,7 +70,7 @@ public function isSubscribed(): bool
7170
/**
7271
* Returns the configuration settings for this consumer instance as array
7372
*
74-
* @return array
73+
* @return string[]
7574
*/
7675
public function getConfiguration(): array
7776
{
@@ -140,7 +139,7 @@ public function getMetadataForTopic(string $topicName): RdKafkaMetadataTopic
140139
*
141140
* @param array|RdKafkaTopicPartition[] $topicPartitions
142141
* @param integer $timeout
143-
* @return array
142+
* @return array|RdKafkaTopicPartition[]
144143
*/
145144
public function offsetsForTimes(array $topicPartitions, int $timeout): array
146145
{

src/Consumer/KafkaConsumerBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class KafkaConsumerBuilder implements KafkaConsumerBuilderInterface
1919
public const CONSUMER_TYPE_HIGH_LEVEL = 'high';
2020

2121
/**
22-
* @var array
22+
* @var string[]
2323
*/
2424
private $brokers = [];
2525

2626
/**
27-
* @var array
27+
* @var array<string, mixed>
2828
*/
2929
private $config = [
3030
'enable.auto.offset.store' => false,
@@ -33,7 +33,7 @@ final class KafkaConsumerBuilder implements KafkaConsumerBuilderInterface
3333
];
3434

3535
/**
36-
* @var array
36+
* @var array|TopicSubscription[]
3737
*/
3838
private $topics = [];
3939

@@ -120,7 +120,7 @@ public function withAdditionalBroker(string $broker): KafkaConsumerBuilderInterf
120120
* Add topic name(s) (and additionally partitions and offsets) to subscribe to
121121
*
122122
* @param string $topicName
123-
* @param array $partitions
123+
* @param int[] $partitions
124124
* @param integer $offset
125125
* @return KafkaConsumerBuilderInterface
126126
*/
@@ -141,7 +141,7 @@ public function withAdditionalSubscription(
141141
* subscribe to
142142
*
143143
* @param string $topicName
144-
* @param array $partitions
144+
* @param int[] $partitions
145145
* @param integer $offset
146146
* @return KafkaConsumerBuilderInterface
147147
*/
@@ -159,7 +159,7 @@ public function withSubscription(
159159
/**
160160
* Add configuration settings, otherwise the kafka defaults apply
161161
*
162-
* @param array $config
162+
* @param string[] $config
163163
* @return KafkaConsumerBuilderInterface
164164
*/
165165
public function withAdditionalConfig(array $config): KafkaConsumerBuilderInterface

src/Consumer/KafkaConsumerBuilderInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function withAdditionalBroker(string $broker): self;
2525
* Add topic name(s) (and additionally partition(s) and offset(s)) to subscribe to
2626
*
2727
* @param string $topicName
28-
* @param array $partitions
28+
* @param int[] $partitions
2929
* @param integer $offset
3030
* @return KafkaConsumerBuilderInterface
3131
*/
@@ -40,7 +40,7 @@ public function withAdditionalSubscription(
4040
* subscribe to
4141
*
4242
* @param string $topicName
43-
* @param array $partitions
43+
* @param int[] $partitions
4444
* @param integer $offset
4545
* @return KafkaConsumerBuilderInterface
4646
*/
@@ -53,7 +53,7 @@ public function withSubscription(
5353
/**
5454
* Add configuration settings, otherwise the kafka defaults apply
5555
*
56-
* @param array $config
56+
* @param string[] $config
5757
* @return KafkaConsumerBuilderInterface
5858
*/
5959
public function withAdditionalConfig(array $config): self;

src/Consumer/KafkaConsumerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function commit($messages): void;
5454
/**
5555
* Returns the configuration settings for this consumer instance as array
5656
*
57-
* @return array
57+
* @return string[]
5858
*/
5959
public function getConfiguration(): array;
6060

@@ -71,7 +71,7 @@ public function getMetadataForTopic(string $topicName): RdKafkaMetadataTopic;
7171
*
7272
* @param array|RdKafkaTopicPartition[] $topicPartitions
7373
* @param integer $timeout
74-
* @return array
74+
* @return array|RdKafkaTopicPartition[]
7575
*/
7676
public function offsetsForTimes(array $topicPartitions, int $timeout): array;
7777

0 commit comments

Comments
 (0)