Skip to content

Commit 3aa4b02

Browse files
Merge pull request #8 from cinemataztic/7-as-big-evil-kafka-i-want-to-update-my-interface-to-be-consistent-with-the-message-passing-taxonomy-so-that-less-mistakes-are-made
Update the interface to ensure that the interface is consistent with the message passing taxonomy
2 parents d653f08 + 2797d61 commit 3aa4b02

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ const client = new KafkaClient({
6565
});
6666
```
6767

68-
## Sending Messages
68+
## Publishing to a Topic
6969

70-
To send a message a topic, provide the topic name and the message.
70+
To publish a message to a topic, provide the topic name and the message.
7171

7272
```js
73-
client.sendMessage(topic, message);
73+
client.publishToTopic(topic, message);
7474
```
7575

76-
## Consuming Messages
76+
## Subscribing to a Topic
7777

7878
The package uses non-flowing consumer mode with `enable.auto.commit` enabled along with `auto.offset.reset` set to earliest.
7979

8080
The messages are consumed at an interval of 1 second with 10 messages consumed at each interval.
8181

82-
To consume a message from a topic, provide the topic name and a callback function that would return the message.
82+
To subscribe to a topic for consuming messages, provide the topic name and a callback function that would return the message.
8383

8484
```js
85-
client.consumeMessage(topic, onMessage);
85+
client.subscribeToTopic(topic, onMessage);
8686
```
8787

8888
## Disconnection

__test__/index.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ describe('Kafka client integration tests', () => {
2222
});
2323

2424
test('should log message when producer is connected', async () => {
25-
await kafkaClient.sendMessage(topic, { message: 'Hello Cinemataztic' });
25+
await kafkaClient.publishToTopic(topic, { message: 'Hello Cinemataztic' });
2626
expect(logSpy).toHaveBeenCalledWith(
2727
'Kafka producer successfully connected',
2828
);
2929
});
3030

3131
test('should log message when consumer is connected', async () => {
32-
await kafkaClient.consumeMessage(topic, () => {});
32+
await kafkaClient.subscribeToTopic(topic, () => {});
3333
expect(logSpy).toHaveBeenCalledWith(
3434
'Kafka consumer successfully connected',
3535
);
3636
});
3737

3838
test('should log message when consumer receives a message', async () => {
39-
await kafkaClient.consumeMessage(topic, (data) => {
39+
await kafkaClient.subscribeToTopic(topic, (data) => {
4040
expect(data).toHaveProperty('value');
4141
expect(data.value).toHaveProperty('message', 'Hello Cinemataztic');
4242
});
@@ -45,7 +45,7 @@ describe('Kafka client integration tests', () => {
4545
await new Promise((resolve) => setTimeout(resolve, 2000));
4646

4747
// Send a message after consumer is ready.
48-
await kafkaClient.sendMessage(topic, { message: 'Hello Cinemataztic' });
48+
await kafkaClient.publishToTopic(topic, { message: 'Hello Cinemataztic' });
4949

5050
// Wait for the polling (via setInterval) to pick up the message.
5151
await new Promise((resolve) => setTimeout(resolve, 5000));

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cinemataztic/big-evil-kafka",
3-
"version": "1.0.10",
3+
"version": "1.1.0",
44
"description": "A wrapper around node-rdkafka",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class KafkaClient {
243243
* @param {Object} message The message to send to a topic
244244
* @public
245245
*/
246-
async sendMessage(topic, message) {
246+
async publishToTopic(topic, message) {
247247
try {
248248
await this.#initProducer();
249249

@@ -277,7 +277,7 @@ class KafkaClient {
277277
* @param {onMessage} onMessage A function that processes the decoded message data received by consumer
278278
* @public
279279
*/
280-
async consumeMessage(topic, onMessage) {
280+
async subscribeToTopic(topic, onMessage) {
281281
try {
282282
await this.#initConsumer();
283283

0 commit comments

Comments
 (0)