Metadata-Version: 2.4
Name: rocketmq3-py-client
Version: 0.3.0
Summary: Python3 client for legacy RocketMQ 3.x clusters (JPype bridge). Supports v3.x ONLY — for 4.x+ use the official rocketmq-client-python.
Author-email: 加帆 <jiafan.zhang@qq.com>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or Derivative
                  Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor.
        
           7. Disclaimer of Warranty. Unless required by applicable law or agreed
              to in writing, Licensor provides the Work (and each Contributor
              provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
              OR CONDITIONS OF ANY KIND, either express or implied.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law shall any Contributor be liable
              to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the Work.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information.
        
           Copyright [2026] [rocketmq-client]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/Jiafan/rocketmq3-py-client
Project-URL: Bug Tracker, https://github.com/Jiafan/rocketmq3-py-client/issues
Project-URL: Documentation, https://github.com/Jiafan/rocketmq3-py-client#readme
Keywords: rocketmq,rocketmq3,rocketmq-3.2.6,messaging,mq,jms
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: <3.13,>=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: JPype1<1.6.0,>=1.5.0
Provides-Extra: test
Requires-Dist: pytest<9.0,>=7.0; extra == "test"
Dynamic: license-file

# rocketmq3-py-client

Python3 RocketMQ 3.x 客户端库，基于 JPype 桥接 RocketMQ Java 客户端。**仅支持 RocketMQ 3.x 老集群**；4.x 及以后请使用官方 `rocketmq-client-python`。

## 特性

- **三种发送模式**：同步、异步、单向（策略模式）
- **两种消费模式**：Pull（主动拉取）、Push（被动推送 / 观察者模式）
- **上下文管理器**：所有客户端支持 `with` 语句，自动释放资源
- **重试机制**：发送失败自动重试，可配置次数和退避策略
- **线程安全**：JVM 单例 + 线程锁
- **完整异常体系**：Java 异常自动翻译为 Python 异常
- **配置驱动**：通过 `ClientConfig` 统一管理参数
- **消息建造者**：链式 API 构建消息

## 环境要求

- Python 3.8 ~ 3.12（已放弃 3.13 / 3.14 支持，换取 JDK 8 兼容性）
- **JDK 8+**（默认依赖 JPype1 1.5.x，官方支持 Java 8；JDK 11+ 亦可向后兼容运行）
- JPype1 >= 1.5.0, < 1.6.0（最后支持 Java 8 的版本线；自带 macOS universal2 预编译包，含 arm64，Apple Silicon 免源码编译）
- RocketMQ 3.2.6 JAR 包（获取方式见下方「获取 RocketMQ Java 客户端」）

> 💡 **本库默认兼容 JDK 8**：只要本机 `JAVA_HOME` 指向 JDK 8（或任意 8+），无需特殊处理即可启动。若需强制指定某个 JDK，仍可用 `java_home`：
> ```python
> config = ClientConfig(namesrv_addr="...", java_home="/Library/Java/JavaVirtualMachines/jdk1.8.0_xxx.jdk/Contents/Home")
> ```
> ⚠️ 注意：JPype1 1.6.0+ 不再支持 Java 8（要求 11+）。如切换到 1.6.0+，须将 `JAVA_HOME` 指向 JDK 11+，且 Python 上限为 3.12（本库已锁定 1.5.x，因此保持 JDK 8 兼容）。

## 获取 RocketMQ 3.2.6 Java 客户端

本库通过 JPype 桥接 RocketMQ 3.2.6 的 Java 客户端，但**不自带 JAR 包**，需自行准备并放到 `ROCKETMQ_LIB_PATH`（默认 `/opt/rocketmq3/lib`），运行时会自动加载该目录下所有 JAR。

> ⚠️ RocketMQ 3.x 使用旧的 `com.alibaba.rocketmq` 命名空间（**不是** 4.x+ 的 `org.apache.rocketmq`），坐标与官方新版完全不同。

### Maven 坐标（Maven Central）

```xml
<dependency>
    <groupId>com.alibaba.rocketmq</groupId>
    <artifactId>rocketmq-client</artifactId>
    <version>3.2.6</version>
</dependency>
```

Maven 仓库地址：
- Maven Central：`https://repo1.maven.org/maven2/com/alibaba/rocketmq/rocketmq-client/3.2.6/`
- 检索页：`https://mvnrepository.com/artifact/com.alibaba.rocketmq/rocketmq-client/3.2.6`

### 已验证的完整依赖清单

以下为 **RocketMQ 3.2.6 运行时所需的最小 JAR 集合**（实测通过）。`rocketmq-client-3.2.6.jar` 本身不内含传递依赖，必须把所有 JAR 放入同一目录，客户端启动时会自动加载。

| JAR | 版本 | 说明 |
|-----|------|------|
| `rocketmq-client-3.2.6.jar` | 3.2.6 | RocketMQ 客户端核心 |
| `rocketmq-common-3.2.6.jar` | 3.2.6 | 消息模型（Message / MessageExt 等） |
| `rocketmq-remoting-3.2.6.jar` | 3.2.6 | 网络通信层（RemotingException 等） |
| `netty-all-4.0.25.Final.jar` | 4.0.25.Final | 网络传输框架（remoting 依赖） |
| `fastjson-1.2.84.jar` | 1.2.84 | JSON 序列化（remoting 依赖） |
| `slf4j-api-1.7.36.jar` | 1.7.36 | 日志接口 |
| `slf4j-simple-1.7.36.jar` | 1.7.36 | 日志实现（可用其他 SLF4J 实现替换） |

> ⚠️ RocketMQ 3.2.6 发布于 2015 年，整体生态较老，仅建议在内网测试环境使用。`fastjson` 已升级到最新的 `1.2.84` 安全修复版。

#### 直接下载

```bash
cd /opt/rocketmq3/lib  # 或 $ROCKETMQ_LIB_PATH

wget "https://repo1.maven.org/maven2/com/alibaba/rocketmq/rocketmq-client/3.2.6/rocketmq-client-3.2.6.jar"
wget "https://repo1.maven.org/maven2/com/alibaba/rocketmq/rocketmq-common/3.2.6/rocketmq-common-3.2.6.jar"
wget "https://repo1.maven.org/maven2/com/alibaba/rocketmq/rocketmq-remoting/3.2.6/rocketmq-remoting-3.2.6.jar"
wget "https://repo1.maven.org/maven2/io/netty/netty-all/4.0.25.Final/netty-all-4.0.25.Final.jar"
wget "https://repo1.maven.org/maven2/com/alibaba/fastjson/1.2.84/fastjson-1.2.84.jar"
wget "https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar"
wget "https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar"
```

### 一键拉取全部依赖 JAR（Maven 方式）

也可以建一个临时 `pom.xml`，用 `maven-dependency-plugin` 把所有传递依赖一次性收集：

```xml
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>tmp</groupId>
  <artifactId>rmq-libs</artifactId>
  <version>1.0</version>
  <dependencies>
    <dependency>
      <groupId>com.alibaba.rocketmq</groupId>
      <artifactId>rocketmq-client</artifactId>
      <version>3.2.6</version>
    </dependency>
  </dependencies>
</project>
```

```bash
mvn dependency:copy-dependencies -DoutputDirectory=.
sudo cp *.jar /opt/rocketmq3/lib/   # 复制到默认加载目录
```

### 自定义 JAR 目录

若不放默认路径，用环境变量指定：

```bash
export ROCKETMQ_LIB_PATH=/path/to/your/rocketmq3/lib
```

## 安装

```bash
pip install rocketmq3-py-client
# 或开发模式
pip install -r requirements.txt
pip install -e .
```

## 快速开始

### 生产者

```python
from rocketmq3_py_client import Producer

with Producer("my_group", "127.0.0.1:9876") as producer:
    result = producer.send("topic", b'{"id": 1}', tags="tag_a", keys="key_1")
    print(result)
```

### Push 消费者

```python
from rocketmq3_py_client import PushConsumer

consumer = PushConsumer("cg", "127.0.0.1:9876", "topic")

@consumer.register_handler
def handle(messages):
    for msg in messages:
        print(msg.msg_id, msg.body)
    return True

consumer.start()
```

### Pull 消费者

```python
from rocketmq3_py_client import PullConsumer

with PullConsumer("cg", "127.0.0.1:9876") as consumer:
    queues = consumer.fetch_message_queues("topic")
    for q in queues:
        result = consumer.pull(q, offset=0, max_nums=32)
        for msg in result.messages:
            print(msg.msg_id, msg.body)
```

