taobao.tmc.messages.consume (消费多条消息)

消费多条消息。消费时如果没有返回消息,建议做控制,不要一直调api,浪费应用的流量。如对程序做好优化,若没有消息则,sleep 100ms 等。

公共参数

请求参数

名称 类型 是否必须 示例值 更多限制 描述
group_name String 可选 vip_user 用户分组名称,不传表示消费默认分组,如果应用没有设置用户分组,传入分组名称将会返回错误
quantity Number 可选 100
  • 默认值:100
  • 每次批量消费消息的条数,最小值:10;最大值:200

    响应参数

    名称 类型 示例值 描述
    messages TmcMessage [] 消息列表
    • └ user_id
    • Number
    • 12345
    • 消息所属的用户编号
    • └ user_nick
    • String
    • helloworld
    • 用户的昵称
    • └ content
    • String
    • {"tid":2895732958732,"seller_nick":"helloworld"}
    • 消息详细内容,格式为JSON/XML
    • └ id
    • Number
    • 123456789
    • 消息ID
    • └ pub_time
    • Date
    • 2000-01-01 00:00:00
    • 消息发布时间
    • └ pub_app_key
    • String
    • 45671234
    • 消息发布者的AppKey
    • └ topic
    • String
    • TradeCreate
    • 消息所属主题

    请求示例

    • JAVA
    • .NET
    • PHP
    • CURL
    • Python
    • C/C++
    • NodeJS
    TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
    TmcMessagesConsumeRequest req = new TmcMessagesConsumeRequest();
    req.setGroupName("vip_user");
    req.setQuantity(100L);
    TmcMessagesConsumeResponse rsp = client.execute(req);
    System.out.println(rsp.getBody());

    响应示例

    • XML示例
    • JSON示例
    <tmc_messages_consume_response>
        <messages>
            <tmc_message>
                <user_id>12345</user_id>
                <user_nick>helloworld</user_nick>
                <content>{&quot;tid&quot;:2895732958732,&quot;seller_nick&quot;:&quot;helloworld&quot;}</content>
                <id>123456789</id>
                <pub_time>2000-01-01 00:00:00</pub_time>
                <pub_app_key>45671234</pub_app_key>
                <topic>TradeCreate</topic>
            </tmc_message>
        </messages>
    </tmc_messages_consume_response>

    异常示例

    • XML示例
    • JSON示例
    <error_response>
        <code>50</code>
        <msg>Remote service error</msg>
        <sub_code>isv.invalid-parameter</sub_code>
        <sub_msg>非法参数</sub_msg>
    </error_response>

    错误码解释

    错误码 错误描述 解决方案
    isv.invalid-param: invalid-group-name 连接分组名称不存在 请输入正确的分组名称,或采用default分组
    isp.system-error: messaging-service error 并发消费同一个分组错误 请减少并发消费的线程和机器数量

    API工具

    如何获得此API

    FAQ

    返回
    顶部