@rocketmq/core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @rocketmq/core
|
|
2
|
+
|
|
3
|
+
The main RocketMQ client SDK for Node.js. It provides a high-level, schema-aware API for AMQP messaging.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Schema-Aware Queues**: Tie a queue directly to a TypeScript class using decorators.
|
|
8
|
+
- **Type-Safe Messaging**: Compile-time type safety for `send()` and `consume()`.
|
|
9
|
+
- **Broker-Side Validation**: Integrates directly with RocketMQ's queue-native schema validation.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @rocketmq/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { connect, Schema, Field } from '@rocketmq/core';
|
|
21
|
+
|
|
22
|
+
@Schema()
|
|
23
|
+
class Order {
|
|
24
|
+
@Field()
|
|
25
|
+
id!: string;
|
|
26
|
+
|
|
27
|
+
@Field({ type: 'int32' })
|
|
28
|
+
quantity!: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function main() {
|
|
32
|
+
const mq = await connect();
|
|
33
|
+
|
|
34
|
+
// Creates a typed queue handle and registers the schema with the broker
|
|
35
|
+
const orders = await mq.queue('orders', Order);
|
|
36
|
+
|
|
37
|
+
// Type-safe consumption
|
|
38
|
+
await orders.consume((order) => {
|
|
39
|
+
console.log(`Received order: ${order.id} for ${order.quantity} items`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Type-safe publishing
|
|
43
|
+
orders.send({ id: '123', quantity: 5 });
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Classic API Style
|
|
48
|
+
|
|
49
|
+
If you prefer the classic AMQP interface over the `QueueHandle` abstraction, you can use `assertQueue` directly while still benefiting from broker-side schema validation and client-side type inference:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
async function classicApiExample() {
|
|
53
|
+
const mq = await connect();
|
|
54
|
+
|
|
55
|
+
// Asserts the queue and registers the schema with the broker
|
|
56
|
+
await mq.assertQueue('orders', Order);
|
|
57
|
+
|
|
58
|
+
// Type-safe consumption
|
|
59
|
+
await mq.consume('orders', (order) => {
|
|
60
|
+
console.log(`Received order: ${order.id} for ${order.quantity} items`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Type-safe publishing
|
|
64
|
+
mq.sendToQueue('orders', { id: '123', quantity: 5 });
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache 2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocketmq/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@rocketmq/
|
|
13
|
-
"@rocketmq/
|
|
14
|
-
"@rocketmq/
|
|
15
|
-
"@rocketmq/
|
|
12
|
+
"@rocketmq/schema": "0.1.1",
|
|
13
|
+
"@rocketmq/serializer": "0.1.1",
|
|
14
|
+
"@rocketmq/protobuf": "0.1.1",
|
|
15
|
+
"@rocketmq/amqp": "0.1.1"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsup",
|