Skip to Content
Agent Data Shuttle 1.0 is out! 🎉
SDKsNode.jsADS Publisher

ADS Publisher

The ADS Publisher allows you to send events to the ADS Subscribers for AI agents to react. This guide covers the essential methods and configuration options for publishing events using the Node.js SDK.

Getting Started

Before you start publishing events, ensure you have the ADS Bridge set up and running.

Initialize Your Publisher

First, set up the connection parameters and create an instance of the ADS Publisher:

import { types, publisher } from "@agentdatashuttle/adsjs"; // Configure RabbitMQ connection parameters that the ADS Bridge also connects to const clientParams = { host: "your-rabbitmq-host", username: "your-rabbitmq-username", password: "your-rabbitmq-password", port: 5672, // Or any other port your RabbitMQ server is running on }; // Create publisher instance const adsPublisher = new publisher.ADSPublisher( "YourEventSource", clientParams );

The eventSource parameter could be any identifier for your event data source, such as “NotionEvents” or “StripeEvents”. It just serves as a reference.

Publish Your Event

Create an event payload and publish it to the ADS Bridge:

// Create event payload const payload = { event_name: "system_alert", event_description: "Critical system event occurred", event_data: { timestamp: new Date().toISOString(), severity: "high", }, }; // Publish the event await adsPublisher.publishEvent(payload);

The eventData field could be any structured data relevant to your event, such as user actions, system metrics, business transactions, etc. to match your use case.

đź’ˇ

Add a straightforward event_name and a detailed event_description to improve the results of the AI agents at the subscriber end (To learn more about this refer here). This also helps provide better reports for the subscribers after the agent invocation is complete.

Configuration

Client Parameters

The ADSRabbitMQClientParams interface defines the connection settings for your RabbitMQ server that the Publisher and Bridge connect to:

const clientParams: types.ADSRabbitMQClientParams = { host: string, username: string, password: string, port: number, };

Use environment variables to store sensitive connection details like passwords and hostnames.

ADSPublisher

Constructor

new publisher.ADSPublisher(eventSource: string, clientParams: ADSRabbitMQClientParams)

Parameters:

  • eventSource (string): Identifier for your event source (e.g., “NotionEvents”, “StripeEvents”)
  • clientParams (ADSRabbitMQClientParams): Connection configuration object

Methods

publishEvent()

Publishes an event to the ADS Bridge for processing.

await adsPublisher.publishEvent(payload: ADSDataPayload): Promise<void>

Parameters:

  • payload (ADSDataPayload): The event data to publish

Data Payload Structure

ADSDataPayload Interface

interface ADSDataPayload { event_name: string; // Short identifier for the event type event_description: string; // Human-readable event description event_data: Record<string, any>; // Custom event data object }

Event Data Examples

const systemEvent = { event_name: "cpu_threshold_exceeded", event_description: "Server CPU usage exceeded 80% threshold", event_data: { server_id: "srv-001", cpu_usage: 85.2, memory_usage: 72.1, timestamp: new Date().toISOString(), alert_level: "warning" } };

Error Handling

⚠️

Always implement proper error handling when publishing events to ensure your application remains stable.

try { await adsPublisher.publishEvent(payload); console.log("Event published successfully"); } catch (error) { console.error("Publishing failed:", error.message); // Implement retry logic or fallback mechanism }

Next Steps

Last updated on