Skip to content
Draft
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
250 changes: 250 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
# How to Release pulsar-client-node

## Overview

This document explains how to release a new version of pulsar-client-node, including how to update the version number in `binding.gyp` for the client description feature.

## Quick Steps for Release

### 1. Update version in package.json

Update the version number in `package.json`:

```bash
npm version <new-version> # e.g., npm version 1.17.0
```

This automatically updates:
- `package.json` version field
- `package-lock.json` (if using npm/yarn)

### 2. Update version in binding.gyp

The version number is **hard-coded** in `binding.gyp` for the client description feature. This ensures the version is fixed at build time and doesn't require dynamic reading from package.json during the build process.

**Location in binding.gyp**:
```json
{
"targets": [
{
"target_name": "pulsar",
"defines": [
"NAPI_VERSION=4",
"PULSAR_CLIENT_NODE_VERSION=\"1.17.0-rc.0\""
]
}
]
}
```

**IMPORTANT**: When updating to a new version, you must manually update the version string in `binding.gyp` to match the new version in `package.json`.

### 3. Run build and tests

```bash
# Clean previous build artifacts
rm -rf lib/ build/ Release/ obj.target/

# Install dependencies and build
npm install

# Run tests
npm test
```

### 4. Publish to npm (if applicable)

```bash
npm publish
```

## Client Description Feature

The client description feature automatically sets the client description to `"node-client-v<version>"` where `<version>` is the version from package.json.

This makes the Node.js client identify itself in broker topic statistics, displaying as:
```
Pulsar-CPP-vX.Y.Z-node-client-vA.B.C
```

## Example: Releasing Version 1.17.0

### Step 1: Update package.json
```bash
npm version 1.17.0
```

### Step 2: Update binding.gyp
Edit `binding.gyp` and change the version string from the old version to the new version:

```diff
- "PULSAR_CLIENT_NODE_VERSION=\"1.16.0\""
+ "PULSAR_CLIENT_NODE_VERSION=\"1.17.0\""
```

### Step 3: Commit changes
```bash
git add package.json binding.gyp
git commit -m "Bump version to 1.17.0"
```

### Step 4: Tag the release
```bash
git tag -a v1.17.0 -m "Release 1.17.0"
```

### Step 5: Push to remote
```bash
git push origin master
git push origin v1.17.0
```

## Automated Version Update Script

To help avoid manually updating `binding.gyp`, you can use the following script:

### `scripts/update_version.sh`

```bash
#!/bin/bash

# Get current version from package.json
CURRENT_VERSION=$(grep '"version"' package.json | head -1 | cut -d: -f4 | cut -d: -f2 | cut -d: -f2 | cut -d: -f3 | cut -d: -f2 | cut -d: -f3 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -当前的版本号会从package.json中读取并设置到 binding.gyp中
# Example: If package.json has "version": "1.17.0", binding.gyp will be updated to "PULSAR_CLIENT_NODE_VERSION=\"1.17.0\""

# 2. 重新生成所有的绑定文件 (如果需要)
# Regenerate binding files if needed (optional, for debugging or ensuring clean build)
rm -rf lib/ build/ Release/ obj.target/

# 3. 提示用户提交
# Prompt user to commit the changes
echo "Done! Version updated in binding.gyp."
echo "Please commit the changes with:"
echo " git add package.json binding.gyp"
echo " git commit -m 'Bump version to $(grep '\"version\"' package.json | head -1 | cut -d: -f4 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: - following: " \
| head -1 | cut -d: -f4 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2 | cut -d: -f2编码问题,这个 bash 脚本有问题。让我重写:</think><tool_call>write<arg_key>content</arg_key><arg_value># How to Release pulsar-client-node

## Overview

This document explains how to release a new version of pulsar-client-node, including how to update the version number in `binding.gyp` for the client description feature.

## Quick Steps for Release

### 1. Update version in package.json

Update the version number in `package.json`:

```bash
npm version <new-version> # e.g., npm version 1.17.0
```

This automatically updates:
- `package.json` version field
- `package-lock.json` (if using npm/yarn)

### 2. Update version in binding.gyp

The version number is **hard-coded** in `binding.gyp` for the client description feature. This ensures the version is fixed at build time and doesn't require dynamic reading from package.json during the build process.

**Location in binding.gyp**:
```json
{
"targets": [
{
"target_name": "pulsar",
"defines": [
"NAPI_VERSION=4",
"PULSAR_CLIENT_NODE_VERSION=\"1.17.0-rc.0\""
]
}
]
}
```

**IMPORTANT**: When updating to a new version, you must manually update the version string in `binding.gyp` to match the new version in `package.json`.

### 3. Run build and tests

```bash
# Clean previous build artifacts
rm -rf lib/ build/ Release/ obj.target/

# Install dependencies and build
npm install

# Run tests
npm test
```

### 4. Publish to npm (if applicable)

```bash
npm publish
```

## Client Description Feature

The client description feature automatically sets the client description to `"node-client-v<version>"` where `<version>` is the version from package.json.

This makes the Node.js client identify itself in broker topic statistics, displaying as:
```
Pulsar-CPP-vX.Y.Z-node-client-vA.B.C
```

## Example: Releasing Version 1.17.0

### Step 1: Update package.json
```bash
npm version 1.17.0
```

### Step 2: Update binding.gyp
Edit `binding.gyp` and change the version string from the old version to the new version:

```diff
- "PULSAR_CLIENT_NODE_VERSION=\"1.16.0\""
+ "PULSAR_CLIENT_NODE_VERSION=\"1.17.0\""
```

### Step 3: Commit changes
```bash
git add package.json binding.gyp
git commit -m "Bump version to 1.17.0"
```

### Step 4: Tag the release
```bash
git tag -a v1.17.0 -m "Release 1.17.0"
```

### Step 5: Push to remote
```bash
git push origin master
git push origin v1.17.0
```

## Automated Version Update Script

To help with updating the version in `binding.gyp`, you can use the following script:

### `scripts/update_version.sh`

```bash
#!/bin/bash

# Get current version from package.json
CURRENT_VERSION=$(grep '"version"' package.json | head -1 | cut -d: -f4 | cut -d: -f2 | cut -d: -f2)

echo "Current version in package.json: $CURRENT_VERSION"
echo "This version will be set in binding.gyp."
read -p "Press Enter to continue, or Ctrl+C to cancel..."

# Extract version from package.json without quotes
VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version"[[:space:]]*:[[:space:]]*//' | sed 's/"[[:space:]]*$//')

# Update binding.gyp with the new version
sed -i.bak "s/PULSAR_CLIENT_NODE_VERSION=\\\"[0-9.\\.]*/PULSAR_CLIENT_NODE_VERSION=\\\"$VERSION\\\"/g" binding.gyp

echo "Updated binding.gyp with version: $VERSION"
echo "Please review the changes with: git diff binding.gyp"
echo "Then commit with: git add binding.gyp && git commit -m 'Bump version to $VERSION'"
25 changes: 12 additions & 13 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand Down Expand Up @@ -27,7 +26,10 @@
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")",
],
"defines": ["NAPI_VERSION=4"],
"defines": [
"NAPI_VERSION=4",
"PULSAR_CLIENT_NODE_VERSION=\"1.17.0-rc.0\""
],
"sources": [
"src/addon.cc",
"src/Message.cc",
Expand All @@ -52,7 +54,7 @@
'MACOSX_DEPLOYMENT_TARGET': '11.0',
'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++17',
'OTHER_CFLAGS': [
"-fPIC",
"-fPIC",
]
},
"dependencies": [
Expand All @@ -77,8 +79,7 @@
"-lpulsar"
]
}]
],
}],
},
['OS=="win"', {
"defines": [
"_HAS_EXCEPTIONS=1",
Expand All @@ -98,7 +99,7 @@
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
]
}],
},
['OS=="linux"', {
"ldflags": [
"-Wl,--exclude-libs,ALL"
Expand All @@ -109,19 +110,17 @@
"conditions": [
['"<!(test -e <(module_root_dir)/pkg/linux/pulsar-cpp && echo true || echo false)"=="true"', {
"include_dirs": [
"<(module_root_dir)/pkg/linux/pulsar-cpp/include"
"<(module_root_dir)/pkg/linux/pulsar-cpp/include"
],
"libraries": [
"<(module_root_dir)/pkg/linux/pulsar-cpp/lib/libpulsarwithdeps.a"
]
"<(module_root_dir)/pkg/linux/pulsar-cpp/lib/libpulsarwithdeps.a"
]
}, {
"libraries": [
"-lpulsar"
]
]
}]
],
}]
]
}],
},
{
"target_name": "action_after_build",
Expand Down
1 change: 1 addition & 0 deletions scripts/src/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define PULSAR_CLIENT_NODE_VERSION "1.17.0-rc.0"
12 changes: 11 additions & 1 deletion src/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <pulsar/c/client.h>
#include <pulsar/c/client_configuration.h>
#include <pulsar/c/result.h>
#include "pulsar/ClientConfiguration.h"
#include <pulsar/ClientConfiguration.h>
#include <sstream>

// Add wrapper for accessing private setDescription
#include "PulsarWrapper.h"

static const std::string CFG_SERVICE_URL = "serviceUrl";
static const std::string CFG_AUTH = "authentication";
Expand Down Expand Up @@ -232,6 +236,12 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
pulsar_client_configuration_set_listener_name(cClientConfig.get(), listenerName.Utf8Value().c_str());
}

// Set client description to identify this as a Node.js client
// Using Node.js client version from package.json
std::ostringstream oss;
oss << "node-client-v" << PULSAR_CLIENT_NODE_VERSION;
pulsar::PulsarWrapper::setClientDescription(cClientConfig.get()->conf, oss.str());

try {
this->cClient = std::shared_ptr<pulsar_client_t>(
pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free);
Expand Down
Loading
Loading