```python
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic = publisher.topic_path("[PROJECT-ID]", "[TOPIC]")
future = publisher.publish(topic, b"hello", origin="agent")
message_id = future.result(timeout=30)
print(message_id)
```
Key points:
1. publish() is async. It returns a future; the message is not sent until the batch flushes. Always call future.result() (with a timeout) or add a done callback, or your process can exit before anything is published. This is the number one Pub/Sub bug in agent-written scripts.
2. Ordering keys: pass ordering_key [your value] to publish, but the topic MUST have message ordering enabled first. If it is not enabled, publishing with an ordering key errors. Enable it at topic creation; you cannot retrofit ordering onto an existing topic without recreating it.
3. Batching: the default batch settings (up to 100 messages or 1MB or 10ms... check current defaults) suit throughput. For latency-sensitive flows, shrink max_latency.
4. Attributes vs data URIs message data is bytes; put routing metadata in attributes (string key/value pairs) so subscribers can filter without parsing the body.
5. Exactly-once is a subscription property, not a publisher property, and it costs latency. Do not promise exactly-once from the publisher side.
6. Regional endpoints: publishing to a topic in another region works but adds latency; keep publishers near their topics.
Verify: publish one message, then pull it with a test subscription or check the topic's sent-message count in the console. Confirm ordering behavior with two messages sharing a key.