update
This commit is contained in:
44
README.md
44
README.md
@@ -248,6 +248,50 @@ export async function searchWines(keyword, config) {
|
||||
}
|
||||
```
|
||||
|
||||
### Example 3: Basic Publish/Subscribe (No Msghandler)
|
||||
|
||||
```javascript
|
||||
import { getNats, subscribe, publish } from './natsClient.js';
|
||||
|
||||
async function basicPubSubExample() {
|
||||
// Connect to NATS
|
||||
await getNats();
|
||||
|
||||
// Subscribe to a topic
|
||||
const subscription = await subscribe('my.topic', (message) => {
|
||||
console.log('Received:', message);
|
||||
});
|
||||
|
||||
// Publish a message
|
||||
await publish('my.topic', { data: 'hello world' });
|
||||
|
||||
// Later, unsubscribe
|
||||
await subscription.unsubscribe();
|
||||
}
|
||||
```
|
||||
|
||||
### Example 4: Direct Request/Reply (No Msghandler)
|
||||
|
||||
```javascript
|
||||
import { getNats, request } from './natsClient.js';
|
||||
|
||||
async function directRequestExample() {
|
||||
// Connect to NATS
|
||||
await getNats();
|
||||
|
||||
// Send a direct request (no msghandler envelope)
|
||||
const response = await request(
|
||||
'sommpanion.backend.dbapi.v1.inbox',
|
||||
JSON.stringify({
|
||||
cmd: 'status',
|
||||
data: {}
|
||||
})
|
||||
);
|
||||
|
||||
console.log('Response:', response);
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Connection Errors
|
||||
|
||||
Reference in New Issue
Block a user