---
Title: Configure attributes
URL Source: https://company-skill.com/p/rocketmq/rocketmq-configure-attributes
Language: en
Description: You want to attach metadata (like tags, keys, timestamps, or custom properties) to RocketMQ messages during production or inspect those attributes during sending or consumption. Typical User…
---

# Configure attributes

Part of **Apache RocketMQ**. Route queries via `POST https://company-skill.com/api/route`.

## What You Want to Do

You want to attach metadata (like tags, keys, timestamps, or custom properties) to RocketMQ messages during production or inspect those attributes during sending or consumption.

**Typical User Questions**:
- How to add tags or keys to messages?
- Can I set custom properties on messages?
- How to inspect message timestamp or origin host?
- How is message ID assigned?
- How to read message properties during consumption?

## Decision Tree

Pick the best path for your situation:

- **If** you are initializing a new `Message` object with `topic`, `body`, `tag`, or `key` → Use **Create Message** (go to *rocketmq/rocketmq-message*)
- **If** you need to set delivery timing via `delayLevel` or configure standard metadata like `setBornHost` or `setBornTimestamp` after message creation but before sending → Use **Manage Message Properties** (go to *rocketmq/rocketmq-message*)
- **If** you are using the **Java SDK** (`rocketmq-client-java>=4.9.0`) and need to retrieve message identifiers (`msgId`), `topic`, or other properties from a `SendResult` during logging or debugging → Use **Manage Message Metadata via Java SDK** (go to *rocketmq/rocketmq-message*)
- **Otherwise (default)** → Start with **Create Message**, as it is required for all message-sending workflows and supports initial property assignment.

## Path Comparison

| Path | Best For | Complexity | Code Required | Automation | Key Fact | Detail Skill |
|------|----------|------------|---------------|------------|----------|-------------|
| Manage Message Properties | When setting or retrieving metadata like delay time, tag, keys, and user-defined properties during message creation. | low | Yes | Yes | Only supports specific metadata (e.g., `born timestamp`, `delayLevel`); cannot set arbitrary custom properties beyond documented parameters | `rocketmq/api/rocketmq-message` |
| Create Message | When constructing a message object with topic, body, tags, keys, and other initial properties. | low | Yes | Yes | Message `body` size limited to 4MB; `tag` max 128 characters | `rocketmq/api/rocketmq-message` |
| Manage Message Metadata via Java SDK | When inspecting or manipulating message properties like IDs, timestamps, hosts, tags, keys, and user-defined properties during production or consumption. | low | Yes | Yes | Requires `rocketmq-client-java>=4.9.0`; only provides getter methods (e.g., `getMessageId`) | `rocketmq/api/rocketmq-message` |

## Path Details

### Path 1: Manage Message Properties

**Best For**: When setting or retrieving metadata like delay time, tag, keys, and user-defined properties during message creation.

**Brief Description**: This capability allows you to configure standard RocketMQ message metadata such as `setBornHost`, `setBornTimestamp`, and `delayLevel`. It is used after a `Message` object exists but before it is sent, enabling control over delivery timing and origin tracking.

**When to Use**:
- Need to configure message delivery timing through `delayLevel` (0–18 range) or absolute timestamp
- Need to set or retrieve standard message metadata like `tag`, `born timestamp`, or `message production timestamp`

**When NOT to Use**:
- Need to construct the initial message object with `topic` and `body` (use **Create Message** path instead)
- Need to inspect message properties during consumption rather than production

**Known Limitations**:
- Only supports setting specific metadata properties like timestamp, host, retry attempts, and delivery time — cannot set arbitrary custom properties beyond documented parameters
- Delay configuration limited to either `delayLevel` (0–18 range) or absolute delivery time with max 40 days delay

### Path 2: Create Message

**Best For**: When constructing a message object with topic, body, tags, keys, and other initial properties.

**Brief Description**: The `Message` constructor in RocketMQ requires a `topic` and `body` (or `messageBody`) and optionally accepts `tag` and `key` for classification and routing. This is the foundational step before any message can be sent.

**When to Use**:
- Initializing a new message object with `topic`, `body`, and optional classification `tag`/`key`
- Setting initial message properties before sending via any delivery pattern (sync/async/oneway)

**When NOT to Use**:
- Need to modify message properties after initial creation (use **Manage Message Properties** path)
- Need to send transactional or ordered messages without first creating the base message object

**Known Limitations**:
- Message `body` size limited to default max 4MB
- `Topic` name constrained to max 255 characters with only alphanumeric, hyphen, and underscore allowed
- `Tag` limited to max 128 characters

### Path 3: Manage Message Metadata via Java SDK

**Best For**: When inspecting or manipulating message properties like IDs, timestamps, hosts, tags, keys, and user-defined properties during production or consumption.

**Brief Description**: Using the **Java SDK** (`rocketmq-client-java`), you can access message metadata after sending via the `SendResult` object. This includes retrieving the assigned message ID, `topic`, and other immutable properties exposed by the SDK.

**Prerequisites**:
- `rocketmq-client-java>=4.9.0`

**When to Use**:
- Need to retrieve message identifiers (`msgId`) or `topic` information from sent messages in Java applications
- Working specifically with RocketMQ **Java SDK** and need to inspect message metadata after sending

**When NOT to Use**:
- Using non-Java SDKs like Python (use general **Manage Message Properties** path instead)
- Need to set message properties rather than retrieve them

**Known Limitations**:
- Requires **Java SDK** version `rocketmq-client-java>=4.9.0`
- Only provides getter methods for existing message properties (e.g., `getMessageId`, `getTopic`) rather than setting new values
- Limited to properties exposed by the `Message` and `SendResult` classes in the **Java SDK**

## FAQ

Q: Which path should I start with?
A: Start with **Create Message**—it’s required to build any message. Add **Manage Message Properties** only if you need to adjust delivery timing or origin metadata before sending.

Q: What if I need to set a custom property like `"userId=123"` but used **Manage Message Metadata via Java SDK**?
A: You’ll hit a limitation—the **Java SDK** path only supports *reading* properties, not setting them. Use **Create Message** or **Manage Message Properties** instead (though note: arbitrary custom properties may not be supported; only documented parameters like `tag` and `key` are guaranteed).

Q: What if I try to inspect the message ID during consumption but used **Create Message** alone?
A: You won’t have access to the final `msgId`—it’s assigned by the broker upon send. You need the **Java SDK** path to retrieve it from the `SendResult`.

Q: Can I use **Manage Message Properties** to set a 50-day delayed message?
A: No—you’ll hit the 40-day maximum delay limit. The `delayLevel` or absolute timestamp in **Manage Message Properties** enforces this cap.

Q: What happens if I use **Manage Message Metadata via Java SDK** in a Python application?
A: It won’t work—the path explicitly requires `rocketmq-client-java>=4.9.0`. Use the general **Manage Message Properties** approach for non-Java environments.

Q: Is the `born timestamp` set automatically, or do I need to call `setBornTimestamp`?
A: It’s usually auto-assigned by the client, but **Manage Message Properties** lets you override it via `setBornTimestamp` if needed for testing or replay scenarios.

## Related queries

configure message metadata, set message tags, add custom message attributes, inspect message timestamp, view message origin host, get message ID, read message properties during consumption, how to add keys to messages, can I set custom properties on messages, how to check message send time, where is

---
Part of [Apache RocketMQ](https://company-skill.com/p/rocketmq.md) · https://company-skill.com/llms.txt
