Skip to content

Connect and decode a first delivery

Ask FeedHub onboarding for the following sandbox settings. Use the exact queue name from the handoff, including its replica suffix if assigned. The virtual host and the FeedHub instance are separate settings.

Environment variable Value from onboarding
FEEDHUB_AMQP_HOST Broker DNS name covered by the server certificate
FEEDHUB_AMQP_PORT AMQPS port
FEEDHUB_AMQP_VHOST RabbitMQ virtual host, such as /
FEEDHUB_AMQP_USERNAME Client username
FEEDHUB_AMQP_PASSWORD Client password supplied through your secret store
FEEDHUB_SNAPSHOT_QUEUE Assigned snapshot queue

Use an assigned sandbox snapshot queue for this smoke check. A successful check removes one delivery from that queue. Run it before starting the application consumer and let the check exit before the application starts. FeedHub provisions the queue and bindings. The script uses the existing queue and the system’s trusted certificate authorities. If onboarding supplies a private CA, pass its PEM bundle through FEEDHUB_AMQP_CA_FILE. TLS verifies the server certificate and the broker hostname in both cases.

Install the client with python -m pip install pika==1.3.2. Supply the settings to the process through your shell or secret manager. Save the script as first_delivery.py and run python first_delivery.py.

import json
import os
import ssl
import sys
from uuid import UUID
import pika
CONTENT_TYPE = "application/vnd.masstransit+json"
TYPES = {
"urn:message:FeedHub.Contracts:EventSnapshot": "EventSnapshot",
"urn:message:FeedHub.Contracts:MarketSnapshot": "MarketSnapshot",
"urn:message:FeedHub.Contracts:EventIndex": "EventIndex",
}
def decode_delivery(properties, body):
if properties.content_type != CONTENT_TYPE:
raise ValueError("unexpected content type")
envelope = json.loads(body.decode("utf-8"))
if not isinstance(envelope, dict):
raise ValueError("invalid envelope")
message_types = envelope.get("messageType")
if not isinstance(message_types, list):
raise ValueError("missing message types")
matches = [urn for urn in TYPES if urn in message_types]
if len(matches) != 1:
raise ValueError("unsupported concrete message type")
payload = envelope.get("message")
if not isinstance(payload, dict):
raise ValueError("missing payload")
version = payload.get("schemaVersion")
if type(version) is not int or version != 1:
raise ValueError("unsupported schema version")
logical_id = payload.get("messageId")
if not isinstance(logical_id, str):
raise ValueError("missing logical message ID")
return TYPES[matches[0]], UUID(logical_id)
def first_delivery():
host = os.environ["FEEDHUB_AMQP_HOST"]
queue = os.environ["FEEDHUB_SNAPSHOT_QUEUE"]
tls = ssl.create_default_context(cafile=os.getenv("FEEDHUB_AMQP_CA_FILE"))
parameters = pika.ConnectionParameters(
host=host,
port=int(os.environ["FEEDHUB_AMQP_PORT"]),
virtual_host=os.environ["FEEDHUB_AMQP_VHOST"],
credentials=pika.PlainCredentials(
os.environ["FEEDHUB_AMQP_USERNAME"],
os.environ["FEEDHUB_AMQP_PASSWORD"],
),
ssl_options=pika.SSLOptions(tls, host),
connection_attempts=1,
socket_timeout=5,
stack_timeout=10,
blocked_connection_timeout=10,
heartbeat=30,
)
with pika.BlockingConnection(parameters) as connection:
channel = connection.channel()
channel.basic_qos(prefetch_count=1)
deliveries = channel.consume(queue, auto_ack=False, inactivity_timeout=15)
delivery, properties, body = next(deliveries)
if delivery is None:
print("No delivery within 15 seconds. Check sandbox feed activity and subscriptions.", file=sys.stderr)
return 1
try:
kind, logical_id = decode_delivery(properties, body)
except ValueError:
channel.basic_nack(delivery_tag=delivery.delivery_tag, requeue=True)
print("Unsupported or malformed delivery. Left it on the queue.", file=sys.stderr)
return 2
print(f"Decoded {kind} with logical message ID {logical_id}", flush=True)
channel.basic_ack(delivery_tag=delivery.delivery_tag)
return 0
if __name__ == "__main__":
try:
sys.exit(first_delivery())
except (KeyError, ValueError, OSError, pika.exceptions.AMQPError):
print("Could not complete the AMQPS check. Verify TLS trust, connection settings and queue access.", file=sys.stderr)
sys.exit(1)

On success, the script prints the concrete type and the logical ID from message.messageId, then acknowledges the current delivery tag on its receiving channel. The AMQP content-type value identifies the JSON envelope format. Use the exact concrete URN in messageType to choose the payload parser. The more general FeedMessage URN can also be present. The script checks the envelope and schema version for this smoke test. For an application, validate and apply the full payload before acknowledging it. Route unreadable deliveries through your processing failure policy so a malformed frame cannot cause an endless retry loop.

See the envelope and AMQP properties and feed payloads for the wire format.

Continue with Bootstrap and recovery to turn the stream into local state.