force-pubsub 0.2.0

Salesforce Pub/Sub API (gRPC) client for force-rs
Documentation

force-pubsub

Crates.io Documentation License

Salesforce Pub/Sub API (gRPC) client for Rust — part of the force-rs workspace.

force-pubsub provides a streaming gRPC client for the Salesforce Pub/Sub API, enabling real-time event consumption and publishing with Avro-encoded Change Data Capture (CDC) events, Platform Events, and custom channels.

Features

  • Subscribe to CDC events, Platform Events, and custom channels with automatic Avro decoding
  • Publish events with schema-aware Avro encoding and delivery confirmation
  • Schema caching with concurrent DashMap-backed cache for high-throughput workloads
  • Reconnection with configurable backoff, replay support, and managed resubscription
  • Authentication via the force crate's Session (Client Credentials, JWT, etc.)

Quick Start

use force_pubsub::{PubSubConfig, PubSubHandler, ReplayPreset};

// Build a force Session first (see force crate docs)
let session = /* ... */;

let config = PubSubConfig::default();
let handler = PubSubHandler::connect(session, config).await?;

// Subscribe to Change Data Capture events
let mut stream = handler
    .subscribe("/data/AccountChangeEvent", ReplayPreset::Latest, None)
    .await?;

while let Some(event) = stream.next().await {
    println!("Received: {:?}", event?);
}

Dependencies

This crate depends on the force crate for authentication and session management.

Live Contract Test

The ignored live smoke test exercises GetTopic and GetSchema against Salesforce's Pub/Sub gRPC endpoint.

SF_PUBSUB_TOPIC=/data/AccountChangeEvent \
cargo test -p force-pubsub --test live_salesforce_pubsub -- --ignored --test-threads=1

SF_PUBSUB_ENDPOINT defaults to https://api.pubsub.salesforce.com:7443. The test reuses the same Salesforce auth environment variables as the core force live tests.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.