We value your privacy

This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content. See our Privacy Policy.

  1. MooseStack
  2. Moose Streams
  3. Stream.send()

Stream.send()

Use Stream.send() to publish one or more records to an existing Stream when the producer can import your Moose SDK models and Stream definition directly. If the producer should only send JSON over HTTP, use an Ingest API instead.

This page covers in-process producers. To define the stream itself, start with Stream.

When to use

Use Stream.send() when the producer can import the stream definition directly, such as an existing app in your monorepo or a Moose workflow.

Use an Ingest API when the producer should only send JSON over HTTP or cannot import Moose objects directly.

Send records

Stream.send() takes one argument. Pass a single record to publish one message, or pass an array or list to publish multiple messages. Moose publishes one stream record per element, not one array payload. There are no per-call options on send().

Send one record:

app/publish.ts
import { userEvents } from "./stream"; await userEvents.send({  id: "evt_1",  userId: "user_123",  timestamp: new Date(),  eventType: "click",});

Send many records:

app/publish.ts
import { userEvents } from "./stream"; await userEvents.send([  { id: "evt_2", userId: "user_456", timestamp: new Date(), eventType: "view" },  { id: "evt_3", userId: "user_789", timestamp: new Date(), eventType: "signup" },]);

Send nothing

This is useful in helper code that batches optional records or filters a collection down to zero results. Top-level empty inputs are valid and send nothing:

app/publish.ts
await userEvents.send(undefined);await userEvents.send(null);await userEvents.send([]);

Behavior

Stream.send() publishes to the stream topic. If the stream also has a destination table, records become queryable only after Moose syncs them into ClickHouse.

If the stream is configured for Schema Registry JSON, send() publishes using the Confluent wire format automatically. See Schema Registry.

Related capabilities

  • Stream for defining the stream resource
  • Sync to table when records should land in ClickHouse
  • Schema registry when payloads should use Confluent Schema Registry
  • Ingest API for external HTTP ingestion into streams

On this page

When to useSend recordsSend nothingBehaviorRelated capabilities
Edit this page
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackHostingTemplatesGuides
Release Notes
Source575
  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Language Server
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streams
    • Define
    • Stream
    • Send
    • Stream.send()
    • Schema registry
    • Process
    • Consumer functions
    • Transform functions
    • Stream patterns
    • Store
    • Sync to table
    • Recover
    • Dead letter queues
  • Moose Workflows
  • Moose APIs & Web Apps
Deployment & Lifecycle
  • Moose Dev
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Query Layer
  • Testing Utilities
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Release Notes
Contribution
  • Documentation
  • Framework

Send one record:

app/publish.ts
import { userEvents } from "./stream"; await userEvents.send({  id: "evt_1",  userId: "user_123",  timestamp: new Date(),  eventType: "click",});

Send many records:

app/publish.ts
import { userEvents } from "./stream"; await userEvents.send([  { id: "evt_2", userId: "user_456", timestamp: new Date(), eventType: "view" },  { id: "evt_3", userId: "user_789", timestamp: new Date(), eventType: "signup" },]);
app/publish.ts
await userEvents.send(undefined);await userEvents.send(null);await userEvents.send([]);