Search in sources :

Example 1 with MediaQueueObject

use of com.qcloud.cos.model.ciModel.queue.MediaQueueObject in project cos-java-sdk-v5 by tencentyun.

the class DocJobDemo method processDocJob.

/**
 * 文档预览完整调用demo
 */
public static void processDocJob(COSClient client) throws InterruptedException {
    String bucketName = "demo-123456789";
    // 1.获取队列id,需要先开启文档预览功能。
    DocQueueRequest queueRequest = new DocQueueRequest();
    queueRequest.setBucketName(bucketName);
    DocListQueueResponse response = client.describeDocProcessQueues(queueRequest);
    List<MediaQueueObject> queueList = response.getQueueList();
    String queueId = "";
    if (queueList.size() != 0) {
        MediaQueueObject mediaQueueObject = queueList.get(0);
        queueId = mediaQueueObject.getQueueId();
    } else {
        System.out.println("获取队列失败");
        return;
    }
    // 2.发送文档预览任务
    // 2.1添加请求参数 参数详情请见api接口文档
    DocJobRequest request = new DocJobRequest();
    request.setBucketName(bucketName);
    DocJobObject docJobObject = request.getDocJobObject();
    docJobObject.setTag("DocProcess");
    docJobObject.getInput().setObject("1.pdf");
    docJobObject.setQueueId(queueId);
    DocProcessObject docProcessObject = docJobObject.getOperation().getDocProcessObject();
    docProcessObject.setQuality("100");
    docProcessObject.setZoom("100");
    docProcessObject.setEndPage("-1");
    docProcessObject.setTgtType("jpg");
    MediaOutputObject output = docJobObject.getOperation().getOutput();
    output.setRegion(client.getClientConfig().getRegion().getRegionName());
    output.setBucket(bucketName);
    output.setObject("demo/pic-${Number}.jpg");
    // 2.2发送预览请求
    DocJobResponse docProcessJobs = client.createDocProcessJobs(request);
    // 3.轮询查询任务结果(也可以配置队列的回调url,使用回调接口获取任务结果)
    DocJobRequest docJobRequest = new DocJobRequest();
    docJobRequest.setBucketName(bucketName);
    String jobId = docProcessJobs.getJobsDetail().getJobId();
    docJobRequest.setJobId(jobId);
    while (true) {
        DocJobResponse docJobResponse = client.describeDocProcessJob(docJobRequest);
        String state = docJobResponse.getJobsDetail().getState();
        // 判断任务状态
        if ("Success".equalsIgnoreCase(state) || "Failed".equalsIgnoreCase(state)) {
            // 处理业务逻辑
            System.out.println(docJobResponse);
            break;
        } else {
            Thread.sleep(500);
        }
    }
}
Also used : DocQueueRequest(com.qcloud.cos.model.ciModel.queue.DocQueueRequest) DocJobResponse(com.qcloud.cos.model.ciModel.job.DocJobResponse) DocJobObject(com.qcloud.cos.model.ciModel.job.DocJobObject) DocListQueueResponse(com.qcloud.cos.model.ciModel.queue.DocListQueueResponse) DocProcessObject(com.qcloud.cos.model.ciModel.job.DocProcessObject) MediaOutputObject(com.qcloud.cos.model.ciModel.common.MediaOutputObject) DocJobRequest(com.qcloud.cos.model.ciModel.job.DocJobRequest) MediaQueueObject(com.qcloud.cos.model.ciModel.queue.MediaQueueObject)

Example 2 with MediaQueueObject

use of com.qcloud.cos.model.ciModel.queue.MediaQueueObject in project cos-java-sdk-v5 by tencentyun.

the class MediaQueueTest method updateMediaQueueTest.

@Test
public void updateMediaQueueTest() {
    if (!judgeUserInfoValid()) {
        return;
    }
    MediaQueueRequest request = new MediaQueueRequest();
    request.setBucketName(bucket);
    MediaListQueueResponse response = cosclient.describeMediaQueues(request);
    if (response != null) {
        List<MediaQueueObject> queueList = response.getQueueList();
        if (queueList.size() != 0) {
            MediaQueueObject mediaQueueObject = queueList.get(0);
            request = new MediaQueueRequest();
            request.setBucketName(bucket);
            request.setQueueId(mediaQueueObject.getQueueId());
            request.getNotifyConfig().setUrl(QUEUE_URL);
            request.setState(QUEUE_STATE);
            request.setName(QUEUE_NAME);
            MediaQueueResponse updateResponse = cosclient.updateMediaQueue(request);
            MediaQueueObject queue = updateResponse.getQueue();
            assertEquals(bucket, queue.getBucketId());
            assertEquals(QUEUE_NAME, queue.getName());
            assertEquals(QUEUE_STATE, queue.getState());
        }
    }
}
Also used : MediaQueueRequest(com.qcloud.cos.model.ciModel.queue.MediaQueueRequest) MediaQueueResponse(com.qcloud.cos.model.ciModel.queue.MediaQueueResponse) MediaListQueueResponse(com.qcloud.cos.model.ciModel.queue.MediaListQueueResponse) MediaQueueObject(com.qcloud.cos.model.ciModel.queue.MediaQueueObject) Test(org.junit.Test)

Aggregations

MediaQueueObject (com.qcloud.cos.model.ciModel.queue.MediaQueueObject)2 MediaOutputObject (com.qcloud.cos.model.ciModel.common.MediaOutputObject)1 DocJobObject (com.qcloud.cos.model.ciModel.job.DocJobObject)1 DocJobRequest (com.qcloud.cos.model.ciModel.job.DocJobRequest)1 DocJobResponse (com.qcloud.cos.model.ciModel.job.DocJobResponse)1 DocProcessObject (com.qcloud.cos.model.ciModel.job.DocProcessObject)1 DocListQueueResponse (com.qcloud.cos.model.ciModel.queue.DocListQueueResponse)1 DocQueueRequest (com.qcloud.cos.model.ciModel.queue.DocQueueRequest)1 MediaListQueueResponse (com.qcloud.cos.model.ciModel.queue.MediaListQueueResponse)1 MediaQueueRequest (com.qcloud.cos.model.ciModel.queue.MediaQueueRequest)1 MediaQueueResponse (com.qcloud.cos.model.ciModel.queue.MediaQueueResponse)1 Test (org.junit.Test)1