Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the interface to ensure that the interface is consistent with the message passing taxonomy #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ const client = new KafkaClient({
});
```

## Sending Messages
## Publishing to a Topic

To send a message a topic, provide the topic name and the message.
To publish a message to a topic, provide the topic name and the message.

```js
client.sendMessage(topic, message);
client.publishToTopic(topic, message);
```

## Consuming Messages
## Subscribing to a Topic

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

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

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

```js
client.consumeMessage(topic, onMessage);
client.subscribeToTopic(topic, onMessage);
```

## Disconnection
Expand Down
8 changes: 4 additions & 4 deletions __test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ describe('Kafka client integration tests', () => {
});

test('should log message when producer is connected', async () => {
await kafkaClient.sendMessage(topic, { message: 'Hello Cinemataztic' });
await kafkaClient.publishToTopic(topic, { message: 'Hello Cinemataztic' });
expect(logSpy).toHaveBeenCalledWith(
'Kafka producer successfully connected',
);
});

test('should log message when consumer is connected', async () => {
await kafkaClient.consumeMessage(topic, () => {});
await kafkaClient.subscribeToTopic(topic, () => {});
expect(logSpy).toHaveBeenCalledWith(
'Kafka consumer successfully connected',
);
});

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

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

// Wait for the polling (via setInterval) to pick up the message.
await new Promise((resolve) => setTimeout(resolve, 5000));
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cinemataztic/big-evil-kafka",
"version": "1.0.10",
"version": "1.1.0",
"description": "A wrapper around node-rdkafka",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class KafkaClient {
* @param {Object} message The message to send to a topic
* @public
*/
async sendMessage(topic, message) {
async publishToTopic(topic, message) {
try {
await this.#initProducer();

Expand Down Expand Up @@ -277,7 +277,7 @@ class KafkaClient {
* @param {onMessage} onMessage A function that processes the decoded message data received by consumer
* @public
*/
async consumeMessage(topic, onMessage) {
async subscribeToTopic(topic, onMessage) {
try {
await this.#initConsumer();

Expand Down
Loading