diff --git a/README.md b/README.md index ead8efb..5dda2f3 100644 --- a/README.md +++ b/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