| Crates.io | lnmp-transport |
| lib.rs | lnmp-transport |
| version | 0.5.16 |
| created_at | 2025-11-24 00:16:01.036863+00 |
| updated_at | 2025-12-19 10:14:41.935333+00 |
| description | Transport bindings for LNMP protocol (HTTP, Kafka, gRPC) |
| homepage | |
| repository | https://github.com/lnmp-protocol/lnmp |
| max_upload_size | |
| id | 1947159 |
| size | 71,361 |
Transport bindings for the LNMP protocol, providing standard mappings between LNMP records with Envelope metadata and various transport protocols (HTTP, Kafka, gRPC).
FID Registry: All examples use official Field IDs from
registry/fids.yaml.
lnmp-transport bridges LNMP's in-memory data model to real-world transport layers by:
LnmpRecord or SemanticChecksumThis crate does NOT:
| Envelope Field | HTTP Header | Example |
|---|---|---|
timestamp |
X-LNMP-Timestamp |
1732373147000 |
source |
X-LNMP-Source |
auth-service |
trace_id |
X-LNMP-Trace-Id |
abc-123-xyz |
| - | traceparent |
00-abc123xyz...-0123456789abcdef-01 |
sequence |
X-LNMP-Sequence |
42 |
labels["key"] |
X-LNMP-Label-key |
prod |
Body: LNMP binary or text format
Content-Type: application/lnmp-binary or application/lnmp-text
| Envelope Field | Kafka Header | Format |
|---|---|---|
timestamp |
lnmp.timestamp |
b"1732373147000" |
source |
lnmp.source |
b"auth-service" |
trace_id |
lnmp.trace_id |
b"abc-123-xyz" |
sequence |
lnmp.sequence |
b"42" |
labels["key"] |
lnmp.label.key |
b"prod" |
Value: LNMP binary format
Recommended Subject Pattern: lnmp.<domain>.<event>
Examples:
lnmp.llm.request - LLM inference requestslnmp.robot.command - Robot control commandslnmp.sensor.telemetry - Sensor data streams| Envelope Field | NATS Header | Format |
|---|---|---|
timestamp |
lnmp-timestamp |
"1732373147000" |
source |
lnmp-source |
"auth-service" |
trace_id |
lnmp-trace-id |
"abc-123-xyz" |
sequence |
lnmp-sequence |
"42" |
labels["key"] |
lnmp-label-key |
"prod" |
Payload: LNMP binary format
| Envelope Field | gRPC Metadata | Example |
|---|---|---|
timestamp |
lnmp-timestamp |
"1732373147000" |
source |
lnmp-source |
"auth-service" |
trace_id |
lnmp-trace-id |
"abc-123-xyz" |
sequence |
lnmp-sequence |
"42" |
labels["key"] |
lnmp-label-key |
"prod" |
Payload Strategy:
bytes fielduse lnmp_transport::grpc;
// Convert envelope metadata to gRPC metadata
let metadata = grpc::envelope_to_metadata(&envelope)?;
for (key, value) in &metadata {
// Attach to gRPC call
println!("{}: {}", key, value);
}
use lnmp_envelope::{LnmpEnvelope, EnvelopeMetadata};
use lnmp_core::{LnmpRecord, LnmpField, LnmpValue};
use lnmp_transport::http;
// Create an envelope
let mut record = LnmpRecord::new();
record.add_field(LnmpField { fid: 12, value: LnmpValue::Int(42) });
let mut meta = EnvelopeMetadata::default();
meta.timestamp = Some(1732373147000);
meta.source = Some("my-service".to_string());
meta.trace_id = Some("trace-abc-123".to_string());
let env = LnmpEnvelope { metadata: meta, record };
// Convert to HTTP headers
let headers = http::envelope_to_headers(&env)?;
// Convert back
let parsed_meta = http::headers_to_envelope_metadata(&headers)?;
assert_eq!(parsed_meta.source, Some("my-service".to_string()));
lnmp-transport automatically generates W3C-compliant traceparent headers for distributed tracing:
use lnmp_transport::http;
let env = /* ... */;
let headers = http::envelope_to_headers(&env)?;
// traceparent header is automatically included if trace_id is present
// Format: 00-{trace_id}-{span_id}-{flags}
To extract trace context from incoming requests:
let trace_id = http::traceparent_to_trace_id(traceparent_header)?;
Note:
lnmp-transportfocuses on trace ID propagation and does not manage the full W3C Trace Context semantics (span parent relationships, sampling decisions, etc.). For complete OpenTelemetry SDK behavior, uselnmp-transportin conjunction with a dedicated tracing library.
http (default): HTTP header mappingskafka: Kafka header mappingsgrpc: gRPC metadata mappingsnats: NATS header mappingsotel: OpenTelemetry integration helpersSee examples/ directory:
transport_basic_usage.rs - Simple mapping examplehttp_full.rs - Complete HTTP request/response with body encodingotel_integration.rs - OpenTelemetry context propagationTo ensure every optional transport binding stays healthy, run the test matrix locally (and wire the same commands into CI):
| Feature flags | Command |
|---|---|
| none | cargo test -p lnmp-transport --no-default-features |
| http (default) | cargo test -p lnmp-transport --features http |
| kafka only | cargo test -p lnmp-transport --no-default-features --features kafka |
| http + kafka | cargo test -p lnmp-transport --features "http kafka" |
| all bindings | cargo test -p lnmp-transport --features "http kafka grpc nats" |
Benchmarks/examples should also be covered in automation at least once per release:
cargo bench -p lnmp-transport --features "http kafka"
cargo bench -p lnmp-transport --no-default-features # verifies graceful skip
cargo run -p lnmp-transport --example transport_basic_usage --features "http kafka grpc nats"
cargo run -p lnmp-transport --example http_full --features http
cargo run -p lnmp-transport --example otel_integration --features http
Tip: Keeping these commands in CI ensures unresolved-import regressions are caught immediately when optional modules change.
This crate follows the same patterns as:
MIT