You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/03 08:06:57 UTC

[GitHub] [pulsar-client-node] BewareMyPower commented on a diff in pull request #255: Change the require path in examples and refactor README

BewareMyPower commented on code in PR #255:
URL: https://github.com/apache/pulsar-client-node/pull/255#discussion_r1038747283


##########
README.md:
##########
@@ -26,77 +26,119 @@ The Pulsar Node.js client can be used to create Pulsar producers and consumers i
 This library works only in Node.js 10.x or later because it uses the
 [node-addon-api](https://github.com/nodejs/node-addon-api) module to wrap the C++ library.
 
-## How to install
+## Getting Started
 
-> **Note**
->
-> These instructions are only available for versions after 1.8.0. For versions previous to 1.8.0, you need to install the C++ client first. Please switch to the corresponding version branch of this repo to read the specific instructions.
-
-### Use `npm`
+To use the Pulsar Node.js client in your project, run:
 
 ```shell
 npm install pulsar-client
 ```
 
-### Use `yarn`
+for `npm` users or
 
 ```shell
 yarn add pulsar-client
 ```
 
-After install, you can run the [examples](https://github.com/apache/pulsar-client-node/tree/master/examples).
+for `yarn` users.
 
-### Prebuilt binaries
+Then you can run the following simple end-to-end example:
 
-The module uses [node-pre-gyp](https://github.com/mapbox/node-pre-gyp) to download the prebuilt binary for your platform, if it exists.
-These binaries are hosted on ASF dist subversion. The following targets are currently provided:
+```javascript
+const Pulsar = require('pulsar-client');
 
-Format: `napi-{platform}-{libc}-{arch}`
-- napi-darwin-unknown-x64.tar.gz
-- napi-linux-glibc-arm64.tar.gz
-- napi-linux-glibc-x64.tar.gz
-- napi-linux-musl-arm64.tar.gz
-- napi-linux-musl-x64.tar.gz
-- napi-win32-unknown-ia32.tar.gz
-- napi-win32-unknown-x64.tar.gz
+(async () => {
+  // Create a client
+  const client = new Pulsar.Client({
+    serviceUrl: 'pulsar://localhost:6650'
+  });
 
-`darwin-arm64` systems are not currently supported, you can refer `How to build` to build from source.
+  // Create a producer
+  const producer = await client.createProducer({
+    topic: 'persistent://public/default/my-topic',
+  });
 
+  // Create a consumer
+  const consumer = await client.subscribe({
+    topic: 'persistent://public/default/my-topic',
+    subscription: 'sub1'
+  });
 
-## How to build
+  // Send a message
+  producer.send({
+    data: Buffer.from("hello")
+  });
 
-### 1. Clone repository.
-```shell
-git clone https://github.com/apache/pulsar-client-node.git
-cd pulsar-client-node
+  // Receive the message 
+  const msg = await consumer.receive();
+  console.log(msg.getData().toString());
+  consumer.acknowledge(msg);
+
+  await producer.close();
+  await consumer.close();
+  await client.close();
+})();
+```
+
+You will see the following output:
+
+```
+hello
 ```
 
-### 2. Install C++ client.
+## More examples 

Review Comment:
   Addressed. Does it make sense to you?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org