Azure Service Bus adapter for gopipe — publish and subscribe with batching, backpressure, lock renewal, and OpenTelemetry metrics.
import (
"github.com/fxsml/gopipe-azservicebus"
"github.com/fxsml/gopipe/message"
)
client, _ := azservicebus.NewClient("Endpoint=sb://...")pub := azservicebus.NewPublisher(client, "my-topic", azservicebus.PublisherConfig{})
// Stream from a channel — batches automatically
pub.Publish(ctx, messages)
// Or send a single batch
pub.PublishBatch(ctx, batch)sub := azservicebus.NewSubscriber(client, "my-topic", "my-subscription", azservicebus.SubscriberConfig{
MaxInFlight: 50,
})
ch, _ := sub.Subscribe(ctx)
for msg := range ch {
// process msg
msg.Ack()
}| Feature | Details |
|---|---|
| Batching | Configurable batch size and flush timeout |
| Backpressure | Semaphore-based in-flight limiting |
| Lock renewal | Auto-detected from broker; configurable override |
| Reconnection | Automatic receiver/sender recreation on failure |
| Graceful shutdown | Drains in-flight messages before closing |
| Telemetry | OpenTelemetry counters and histograms |
| CloudEvents | Preserves CloudEvents AMQP properties |
| Auth | Connection string or DefaultAzureCredential |
go get github.com/fxsml/gopipe-azservicebusA command-line tool for publishing and subscribing to Azure Service Bus using JSONL (JSON Lines).
go install github.com/fxsml/gopipe-azservicebus/cmd/gopipe-azservicebus@latestPass the Service Bus connection string via flag or environment variable:
export SERVICEBUS_CONNECTION="Endpoint=sb://..."
# or per-command: --connection "Endpoint=sb://..."
# or via env file: --env-file .env.localRead JSONL from stdin or a file and publish to a topic:
# from stdin
echo '{"specversion":"1.0","type":"com.example.event","source":"/test","id":"1"}' \
| gopipe-azservicebus pub --topic my-topic
# from file
gopipe-azservicebus pub --topic my-topic --input-file events.jsonlReceive messages and write them as JSONL to stdout or a file:
# to stdout (Ctrl+C to stop)
gopipe-azservicebus sub --subscription my-topic/my-subscription
# to file, stop after 100 messages or 30 seconds
gopipe-azservicebus sub --subscription my-topic/my-subscription \
--output-file out.jsonl --limit 100 --timeout 30s
# non-destructive peek (messages are not acknowledged)
gopipe-azservicebus sub --subscription my-topic/my-subscription --peekSee KNOWN-ISSUES.md for documented edge cases and mitigations.
MIT