Configuration

更新时间:
复制 MD 格式

This topic answers frequently asked questions about message queue configuration.

How long are messages stored on the server?

Messages are stored for up to 3 days. Unconsumed messages are deleted after 3 days.

What is the maximum size of a message body?

The maximum message size depends on the message type. The limits are as follows:

  • Normal messages and ordered messages: 4 MB

  • Transactional messages and scheduled and delayed messages: 4 MB

How do I set the number of consumer threads for a client?

You can set the ConsumeThreadNums property when you start the consumer. The following code provides an example.

public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.GROUP_ID, "GID_001");
        // An AccessKey for an Alibaba Cloud account grants full access to all APIs and poses a high security threat. For better security, create and use a RAM user for API access or daily O&M. To create a RAM user, log on to the RAM console.
        // This example shows how to save the AccessKey and AccessKeySecret as environment variables.
        // Do not hardcode the AccessKey and AccessKeySecret into your code. This can lead to key leakage.
        properties.put(PropertyKeyConst.AccessKey, "SOFA_AK_ENV");
        properties.put(PropertyKeyConst.SecretKey, "SOFA_SK_ENV");
        /**
         * Set the number of consumer threads to 20.
         */
        properties.put(PropertyKeyConst.ConsumeThreadNums, 20);
        Consumer consumer = ONSFactory.createConsumer(properties);
        consumer.subscribe("TestTopic", "*", new MessageListener() {
            publicAction consume(Message message, ConsumeContext context) {
                System.out.println("Receive: " + message);
                return Action.CommitMessage;
            }
        });
        consumer.start();
        System.out.println("Consumer Started");
}