Skip to content

Commit 671a7f9

Browse files
authoredApr 8, 2020
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

+16
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

+3-2
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

+4-4
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

+1-1
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

+2-1
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

+8-8
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

+2-3
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

+6-6
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

+3-3
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

+2-2
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

‎src/Consumer/KafkaHighLevelConsumer.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function commit($messages): void
9999
/**
100100
* Assigns a consumer to the given TopicPartition(s)
101101
*
102-
* @param array $topicPartitions
102+
* @param string[]|RdKafkaTopicPartition[] $topicPartitions
103103
* @throws KafkaConsumerAssignmentException
104104
* @return void
105105
*/
@@ -127,7 +127,7 @@ public function commitAsync($messages): void
127127
/**
128128
* Gets the current assignment for the consumer
129129
*
130-
* @return array
130+
* @return array|RdKafkaTopicPartition[]
131131
* @throws KafkaConsumerAssignmentException
132132
*/
133133
public function getAssignment(): array
@@ -160,7 +160,7 @@ public function getCommittedOffsets(array $topicPartitions, int $timeout): array
160160
* Get current offset positions of the consumer
161161
*
162162
* @param array|RdKafkaTopicPartition[] $topicPartitions
163-
* @return array
163+
* @return array|RdKafkaTopicPartition[]
164164
*/
165165
public function getOffsetPositions(array $topicPartitions): array
166166
{
@@ -211,8 +211,8 @@ private function commitMessages($messages, bool $asAsync = false): void
211211
}
212212

213213
/**
214-
* @param array $messages
215-
* @return array
214+
* @param array|KafkaConsumerMessageInterface[] $messages
215+
* @return array|RdKafkaTopicPartition[]
216216
*/
217217
private function getOffsetsToCommitForMessages(array $messages): array
218218
{

‎src/Consumer/KafkaHighLevelConsumerInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface KafkaHighLevelConsumerInterface extends KafkaConsumerInterface
1212
/**
1313
* Assigns a consumer to the given TopicPartition(s)
1414
*
15-
* @param array $topicPartitions
15+
* @param string[]|RdKafkaTopicPartition[] $topicPartitions
1616
* @return void
1717
*/
1818
public function assign(array $topicPartitions): void;
@@ -45,7 +45,7 @@ public function getCommittedOffsets(array $topicPartitions, int $timeout): array
4545
* Get current offset positions of the consumer
4646
*
4747
* @param array|RdKafkaTopicPartition[] $topicPartitions
48-
* @return array
48+
* @return array|RdKafkaTopicPartition[]
4949
*/
5050
public function getOffsetPositions(array $topicPartitions): array;
5151

‎src/Consumer/KafkaLowLevelConsumer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function kafkaConsume(int $timeout): ?RdKafkaMessage
151151

152152
/**
153153
* @param string $topic
154-
* @return array
154+
* @return int[]
155155
* @throws RdKafkaException
156156
*/
157157
private function getAllTopicPartitions(string $topic): array

‎src/Consumer/TopicSubscription.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class TopicSubscription implements TopicSubscriptionInterface
2424

2525
/**
2626
* @param string $topicName
27-
* @param array $partitions
27+
* @param int[] $partitions
2828
* @param integer $offset
2929
*/
3030
public function __construct(
@@ -46,7 +46,7 @@ public function getTopicName(): string
4646
}
4747

4848
/**
49-
* @param array $partitions
49+
* @param int[] $partitions
5050
* @return void
5151
*/
5252
public function setPartitions(array $partitions): void

‎src/Consumer/TopicSubscriptionInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ interface TopicSubscriptionInterface
1313
public function getTopicName(): string;
1414

1515
/**
16-
* @return array
16+
* @return int[]
1717
*/
1818
public function getPartitions(): array;
1919

2020
/**
21-
* @param array $partitions
21+
* @param int[] $partitions
2222
* @return void
2323
*/
2424
public function setPartitions(array $partitions): void;

‎src/Message/AbstractKafkaMessage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class AbstractKafkaMessage implements KafkaMessageInterface
2828
protected $partition;
2929

3030
/**
31-
* @var array|null
31+
* @var string[]|null
3232
*/
3333
protected $headers;
3434

@@ -65,7 +65,7 @@ public function getPartition(): int
6565
}
6666

6767
/**
68-
* @return array|null
68+
* @return string[]|null
6969
*/
7070
public function getHeaders(): ?array
7171
{

‎src/Message/KafkaConsumerMessage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class KafkaConsumerMessage extends AbstractKafkaMessage implements KafkaCo
2525
* @param integer $timestamp
2626
* @param string|null $key
2727
* @param mixed $body
28-
* @param array|null $headers
28+
* @param string[]|null $headers
2929
*/
3030
public function __construct(
3131
string $topicName,

‎src/Message/KafkaMessageInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getTopicName(): string;
2323
public function getPartition(): int;
2424

2525
/**
26-
* @return array|null
26+
* @return string[]|null
2727
*/
2828
public function getHeaders(): ?array;
2929

‎src/Message/KafkaProducerMessage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function withBody($body): KafkaProducerMessageInterface
5454
}
5555

5656
/**
57-
* @param array|null $headers
57+
* @param string[]|null $headers
5858
* @return KafkaProducerMessageInterface
5959
*/
6060
public function withHeaders(?array $headers): KafkaProducerMessageInterface

0 commit comments

Comments
 (0)
Please sign in to comment.