Introducing a new way to review your PRs.

Read the announcement

floci-io / floci-az

Light, fluffy, and always free - Local Azure Emulator

View on GitHub

27 documents · Updated Nov 23, 2026

docs / service-bus-artemis-integration

Service Bus Artemis integration

The Service Bus Artemis integration adapts the local Artemis broker and its Proton AMQP engine to the wire and message rules expected by Azure Service Bus clients. It combines protocol patches, broker plugins, and per-namespace provisioning so the emulator can provide CBS authentication, duplicate detection, expiry, dead-lettering, peeking, batching, locks, and sessions.

See the parent overview in Service Bus.

Integration role

Artemis provides queueing, routing, and broker life-cycle services. The integration adds the Service Bus behavior that clients need at the AMQP boundary and connects each entity's management settings to the matching broker policy.

BoundaryService Bus behavior
Connection securityAccepts the Service Bus CBS SASL mechanism used by AMQP clients.
Message transferHandles delivery identity, batches, credit, and transfer state in a Service Bus-compatible way.
Message metadataExposes sequence, enqueue time, delivery count, lock, and session data.
Message outcomesPreserves dead-letter information and reports expired locks.
Broker policyApplies duplicate detection, expiry, and dead-letter routing.
Management linksSupports non-destructive peeking and lock renewal.
Session linksReserves, renews, reports, and releases exclusive sessions.

Namespace broker lifecycle

Each live Service Bus namespace runs in its own Artemis container. The container receives a generated broker configuration, TLS material, the local Artemis extension, and the Proton and AMQP patch resources before it starts. ServiceBusNamespaceManager then provisions queues, topics, subscriptions, management addresses, dead-letter queues, and policy settings through Jolokia. src/…/ServiceBusNamespaceManager.java• L160-248, src/…/ServiceBusNamespaceManager.java• L419-458, src/…/ServiceBusNamespaceManager.java• L565-609

The static broker configuration contains the AMQP acceptors, the shared dead-letter address, and the CBS request path. Entity topology is created later by management operations rather than being fixed when the broker starts. ServiceBusConfigGenerator also enables the duplicate, expiry, and peek plugins for the namespace. src/…/ServiceBusConfigGenerator.java• L9-15, src/…/ServiceBusConfigGenerator.java• L29-95

The Service Bus container manager controls when this runtime exists. A topology file takes precedence over start-on-boot settings. Without either mode, a real namespace starts on its first entity-management call; mocked mode keeps only management-plane state and has no AMQP broker. src/…/ServiceBusContainerManager.java• L39-80, src/…/ServiceBusNamespaceManager.java• L318-329

This diagram shows the relationship between namespace startup, broker setup, and dynamic entity provisioning.

flowchart LR
    Startup[Service startup] --> Mode{Topology file or start mode}
    Mode --> Container[Namespace Artemis container]
    Container --> Resources[Broker config, TLS, patches, plugins]
    Resources --> AMQP[AMQP and AMQPS endpoints]
    Management[Entity management API] --> Jolokia[Jolokia provisioning]
    Jolokia --> Entities[Queues, topics, subscriptions, DLQs, management nodes]
    Entities --> AMQP

References: src/…/ServiceBusConfigGenerator.java• L9-15 src/…/ServiceBusConfigGenerator.java• L29-95 src/…/ServiceBusContainerManager.java• L39-80 src/…/ServiceBusNamespaceManager.java• L160-248 src/…/ServiceBusNamespaceManager.java• L318-329 src/…/ServiceBusNamespaceManager.java• L419-458 src/…/ServiceBusNamespaceManager.java• L565-609

AMQP protocol boundary

The AMQP boundary is the path between a Service Bus client and the Artemis broker. Proton patches keep transport and link state compatible with Service Bus clients, while the Artemis AMQP patches translate Service Bus message and delivery rules into broker operations.

This diagram shows how connection setup and message operations cross the patched AMQP boundary.

flowchart LR
    Client[Service Bus AMQP client] --> SASL[MSSBCBS authentication]
    SASL --> Proton[Patched Proton transport and links]
    Proton --> AMQP[Patched Artemis AMQP handling]
    AMQP --> Broker[Artemis queues and addresses]
    Broker --> Policy[Duplicate, expiry, and dead-letter policy]
    Client --> Management[Peek or renew management link]
    Management --> AMQP

CBS authentication

CBS authentication is exposed as the MSSBCBS SASL mechanism. The broker accepts this local compatibility exchange so a Service Bus client can establish its AMQP connection before it accesses an entity. src/…/ServiceBusConfigGenerator.java• L36-50, src/…/MssbcbsServerSaslFactory.java• L12-36

The mechanism is a broker-side emulator trust boundary. It supports the expected protocol name and exchange; it is not a full Azure token authority. src/…/MssbcbsServerSasl.java• L7-29

References: src/…/ServiceBusConfigGenerator.java• L36-50 src/…/MssbcbsServerSasl.java• L7-29 src/…/MssbcbsServerSaslFactory.java• L12-36

AMQP transfer behavior

Transfer behavior keeps delivery state compatible with Service Bus clients. New deliveries receive unique 16-byte tags that can serve as lock-token identities, and batched transfers are split into individual AMQP messages before normal routing. src/…/AmqpTransferTagGenerator.java• L13-49, src/…/ServiceBusBatchSupport.java• L18-65

The Proton link patch supplies finite receiver message-size behavior, preserves credit and drain state, and applies the AMQP zero value when a pre-settled link omits delivery count. These rules protect the first transfer as well as later message flow. src/…/ReceiverImpl.java• L29-79, src/…/TransportLink.java• L28-45

References: src/…/AmqpTransferTagGenerator.java• L13-49 src/…/ServiceBusBatchSupport.java• L26-65 src/…/ReceiverImpl.java• L29-79 src/…/TransportLink.java• L28-45

Delivery metadata

Delivery metadata gives outgoing Service Bus messages an entity-local view of broker state. The integration derives sequence, enqueue time, and delivery count from the broker and adds lock data when the queue uses peek-lock behavior. src/…/ServiceBusMessageMetadataSupport.java• L15-75, src/…/ServiceBusMessageLockSupport.java• L182-190

Metadata is added at delivery time so shared broker state does not gain client-specific annotations. Large-message movement also clears an old expiry deadline when a streamed message is copied for expiry or dead-letter handling. src/…/ServiceBusMessageMetadataSupport.java• L25-52, src/…/ServiceBusLargeMessageSupport.java• L16-61

References: src/…/ServiceBusMessageMetadataSupport.java• L15-75 src/…/ServiceBusMessageLockSupport.java• L182-190 src/…/ServiceBusLargeMessageSupport.java• L16-61

Message locks

Message locks provide timed ownership for non-pre-settled deliveries on queues configured for peek-lock behavior. The integration exposes the deadline, watches for expiry, and cancels an expired delivery so a late settlement reports com.microsoft:message-lock-lost instead of changing a later delivery. src/…/ServiceBusMessageLockSupport.java• L26-68, src/…/ServiceBusMessageLockSupport.java• L140-174

Renewal checks the entity, link, and 16-byte token before extending ownership. If cancellation of an expired delivery does not complete safely, the connection closes to protect a newer delivery from stale lock state. src/…/ServiceBusMessageLockSupport.java• L71-109, src/…/ServiceBusMessageLockSupport.java• L151-164

References: src/…/ServiceBusMessageLockSupport.java• L26-68 src/…/ServiceBusMessageLockSupport.java• L71-109 src/…/ServiceBusMessageLockSupport.java• L140-174

Lock renewal

Lock renewal uses an entity management link as a request and response path. A message request carries one or more lock tokens, while a session request carries a session ID; successful responses return new expiry values and invalid ownership returns Service Bus error status. src/…/ServiceBusLockRenewalSupport.java• L17-27, src/…/ServiceBusLockRenewalSupport.java• L43-101

The request runs on the requesting connection and stays tied to the link and entity that own the delivery or session. This prevents a valid-looking renewal from changing unrelated ownership. src/…/ServiceBusLockRenewalSupport.java• L26-43, src/…/ServiceBusSessionSupport.java• L124-149

References: src/…/ServiceBusLockRenewalSupport.java• L17-27 src/…/ServiceBusLockRenewalSupport.java• L43-101 src/…/ServiceBusSessionSupport.java• L124-149

Dead-letter outcomes

Dead-letter outcomes preserve client-supplied rejection data as a message moves to the dead-letter destination. The AMQP rejection is converted into broker-safe message properties so the later dead-letter read can expose the reason to the Service Bus client. src/…/ServiceBusDeadLetterSupport.java• L12-43

References: src/…/ServiceBusDeadLetterSupport.java• L18-43

Broker behavior

Broker plugins apply Service Bus rules at routing and queue-delivery points. They use Artemis queue and scheduling behavior while adding policy that depends on an address, queue, or delivery.

Duplicate detection

Duplicate detection treats a message ID as the identity key for a configured address. The plugin accepts the first ID, rejects later copies during the configured history window, and removes the ID when that window ends. Messages without an ID and addresses without a configured window pass through. src/…/ServiceBusDuplicateDetectionPlugin.java• L18-24, src/…/ServiceBusDuplicateDetectionPlugin.java• L76-170

Entity creation applies this policy to queue or topic addresses through the duplicate-detection management service. Subscription queues can therefore have their own duplicate scope. src/…/ServiceBusNamespaceManager.java• L536-554, src/…/ServiceBusNamespaceManager.java• L602-608

References: src/…/ServiceBusDuplicateDetectionPlugin.java• L18-24 src/…/ServiceBusDuplicateDetectionPlugin.java• L76-170 src/…/ServiceBusNamespaceManager.java• L536-554 src/…/ServiceBusNamespaceManager.java• L602-608

Expiry and dead-letter routing

Expiry gives a configured queue a default message lifetime. The plugin uses the shorter of the message expiry and queue default, then either removes the expired message or moves it to the queue's dead-letter address. src/…/ServiceBusExpiryPlugin.java• L25-31, src/…/ServiceBusExpiryPlugin.java• L114-185

Expiry is configured per queue because subscription queues can have different lifetime rules even when they receive messages from the same topic. A message in active delivery is not removed by the scheduled expiry task, and acknowledgement or movement cancels its pending expiry. src/…/ServiceBusExpiryPlugin.java• L188-253, src/…/ServiceBusNamespaceManager.java• L428-458, src/…/ServiceBusNamespaceManager.java• L576-609

References: src/…/ServiceBusExpiryPlugin.java• L25-31 src/…/ServiceBusExpiryPlugin.java• L114-185 src/…/ServiceBusExpiryPlugin.java• L188-253 src/…/ServiceBusNamespaceManager.java• L428-458 src/…/ServiceBusNamespaceManager.java• L576-609

Peek requests

Peek is a non-destructive read through an entity's /$management AMQP node. The peek plugin consumes the management request instead of forwarding it to response subscribers, then reads bounded results from the queue without removing them. src/…/ServiceBusPeekPlugin.java• L31-83

The request can start at a sequence number, limit the result count, select a session, and omit message bodies. The response returns Service Bus sequence and enqueue-time annotations with status values for success, no content, invalid input, missing entities, and server errors. src/…/ServiceBusPeekPlugin.java• L94-133, src/…/ServiceBusPeekPlugin.java• L150-290

References: src/…/ServiceBusPeekPlugin.java• L31-83 src/…/ServiceBusPeekPlugin.java• L94-133 src/…/ServiceBusPeekPlugin.java• L150-290

Topic and subscription routing

Topic routing separates sender ingress from subscription delivery. The namespace manager creates an ingress address and a hidden multicast address, then uses diverts to copy matching messages into each subscription's anycast queue. Subscription filters therefore control which queues receive a topic message. src/…/ServiceBusNamespaceManager.java• L484-507, src/…/ServiceBusNamespaceManager.java• L557-609

The same provisioning step gives each subscription its own management address, dead-letter queue, expiry policy, and optional duplicate-detection scope. A filter can be updated without interrupting the subscription queue or its receivers. src/…/ServiceBusNamespaceManager.java• L612-621, src/…/ServiceBusNamespaceManager.java• L624-652

References: src/…/ServiceBusNamespaceManager.java• L484-507 src/…/ServiceBusNamespaceManager.java• L557-609 src/…/ServiceBusNamespaceManager.java• L612-652

Session links provide exclusive access to messages with the same session ID. The integration maps session selection to Artemis message groups, reserves one group for a sender link, and supports either a named session or the next available session. src/…/ServiceBusSessionSupport.java• L44-110, src/…/ServiceBusSessionSupport.java• L179-249

The client receives the selected session ID and its lock deadline. Release ends ownership; expiry resets the group and closes the sender with a Service Bus session-lock error. A management request can renew a valid session lock before the deadline. src/…/ServiceBusSessionSupport.java• L103-149, src/…/ServiceBusSessionSupport.java• L252-275

Queue provisioning marks session queues with the metadata read by the patched AMQP layer and uses ungrouped dead-letter queues so a dead-lettered session message does not remain pinned to one consumer. src/…/ServiceBusNamespaceManager.java• L729-745

References: src/…/ServiceBusSessionSupport.java• L44-176 src/…/ServiceBusSessionSupport.java• L179-275 src/…/ServiceBusNamespaceManager.java• L729-745

Declarative topology loading

The topology loader can start namespaces and create Service Bus entities from the official emulator Config.json shape. It sends those declarations through the same management paths used by SDK calls, so validation, entity state, and Artemis provisioning follow one contract. src/…/ServiceBusTopologyLoader.java• L19-31, src/…/ServiceBusTopologyLoader.java• L74-117

For each entity, the loader maps duplicate detection, message lifetime, delivery, and session settings into the provisioning request. It also turns correlation and SQL rules into the selector model used by subscription routing. src/…/ServiceBusTopologyLoader.java• L163-224, src/…/ServiceBusTopologyLoader.java• L318-389

Rule replacement is atomic from the topology view. Valid declarations replace the full rule set and remove the implicit $Default rule; a rejected reload keeps an existing subscription unchanged, while a new subscription keeps the default rule when all declared rules fail validation. Forwarding declarations are logged as unsupported rather than emulated. src/…/ServiceBusTopologyLoader.java• L240-300, src/…/ServiceBusTopologyLoader.java• L392-397

This diagram shows the topology path from a declarative file to broker entities and subscription selectors.

flowchart TD
    Config[Service Bus topology file] --> Loader[Topology loader]
    Loader --> Handler[Shared Service Bus management paths]
    Handler --> Namespace[Namespace manager]
    Namespace --> Broker[Artemis entities and policies]
    Loader --> Rules[Validated subscription rules]
    Rules --> Diverts[Subscription routing filters]

References: src/…/ServiceBusContainerManager.java• L58-63 src/…/ServiceBusTopologyLoader.java• L19-31 src/…/ServiceBusTopologyLoader.java• L74-117 src/…/ServiceBusTopologyLoader.java• L163-224 src/…/ServiceBusTopologyLoader.java• L240-300 src/…/ServiceBusTopologyLoader.java• L318-397

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the MSSBCBS name aligned between generated acceptors and the SASL factory. A mismatch blocks clients before entity access.
  • Keep patch resource versions aligned with the Artemis image and container paths. A namespace can start with incompatible protocol classes and fail only during AMQP use.
  • Keep queue names, dead-letter queue suffixes, management suffixes, and topic divert names aligned between provisioning and AMQP path handling.
  • Keep session and peek-lock metadata prefixes aligned with the patched AMQP readers. A change can silently disable session or lock behavior.
  • Keep duplicate-detection addresses aligned with message-ID scope and subscription routing. A wrong address changes which deliveries count as duplicates.
  • Keep queue expiry settings aligned with each subscription queue and its dead-letter destination. Topic settings do not replace per-queue lifetime rules.
  • Keep topology-loader rule replacement aligned with the shared management paths. Direct broker creation can bypass validation or leave selector state inconsistent.
  • Keep the topology loader's default-rule behavior aligned with rejected and empty rule declarations. It changes which messages a new subscription receives.
  • Keep peek and lock-renewal request fields, response annotations, and status values aligned with the management-link clients.
  • Keep unique delivery tags and stale-lock checks aligned. Reused transport resources must not reuse lock ownership.

Important failure modes

TriggerConsequenceGuard
A broker starts without a matching Proton or AMQP patch resource.The namespace may fail on the first CBS link or transfer rather than at container creation.Keep embedded patch resources compatible with the configured Artemis image.
A queue or subscription is created without matching lock or session metadata.Clients receive ordinary delivery behavior instead of peek-lock or session semantics.Apply queue metadata during every entity provisioning path.
A topic divert or subscription filter uses the wrong address name.Messages do not reach the intended subscription or reach the wrong one.Preserve the ingress, hidden multicast, subscription, and divert naming contract.
A message has no ID while duplicate detection is enabled.The message bypasses duplicate detection.Require message IDs when duplicate protection is part of the client contract.
A queue expiry policy points to the wrong dead-letter address.Expired messages are removed or routed to the wrong destination.Configure expiry and dead-letter settings together for each queue.
A peek request has invalid fields or an unknown entity.The management link returns an error or no-content status instead of a peek result.Send the required request fields and preserve management address names.
A lock renewal uses a stale token, entity, link, or session ID.The renewal reports lock loss and leaves active ownership unchanged.Match renewal identity to the owning delivery or session.
A session lock expires before renewal or release.The group is released and the sender link closes with a session-lock error.Renew or reacquire the session before its deadline.
A topology file contains only rejected rules for a new subscription.The subscription keeps the implicit $Default rule and may receive more messages than intended.Treat rule validation and default-rule fallback as one contract.
A topology file declares forwarding settings.The entities are created without auto-forwarding.Do not rely on ForwardTo or ForwardDeadLetteredMessagesTo in this emulator path.

Key files

FileWhy to read it
src/…/ServiceBusConfigGenerator.javaShows the static broker boundary, enabled plugins, CBS acceptors, and shared addresses.
src/…/ServiceBusContainerManager.javaShows namespace startup modes, topology precedence, mocked mode, and shutdown.
src/…/ServiceBusNamespaceManager.javaShows how a namespace receives patches and how queues, topics, subscriptions, policies, and management nodes are provisioned.
src/…/ServiceBusTopologyLoader.javaShows how declarative topology becomes shared management operations and subscription rules.
src/…/MssbcbsServerSaslFactory.javaShows how the Service Bus SASL mechanism enters Artemis.
src/…/TransportLink.javaShows Proton transport state needed by Service Bus links.
src/…/ReceiverImpl.javaShows receiver defaults and credit behavior used during transfer.
src/…/ServiceBusBatchSupport.javaShows how Service Bus batches become individual broker messages.
src/…/ServiceBusMessageMetadataSupport.javaShows outgoing sequence, enqueue-time, delivery-count, and lock metadata.
src/…/ServiceBusMessageLockSupport.javaShows delivery lock ownership, expiry, stale settlement handling, and renewal.
src/…/ServiceBusLockRenewalSupport.javaShows management-link renewal requests and responses.
src/…/ServiceBusSessionSupport.javaShows session selection, exclusive ownership, renewal, and lock loss.
src/…/ServiceBusDuplicateDetectionPlugin.javaShows message-ID history and duplicate scope.
src/…/ServiceBusExpiryPlugin.javaShows queue lifetime and expiry movement.
src/…/ServiceBusPeekPlugin.javaShows the non-destructive management-link read path.
src/…/ServiceBusDeadLetterSupport.javaShows how rejected-delivery data follows a message into dead lettering.