Manage pipelines
A pipeline queues asynchronous tasks and executes them by priority and submission order. This topic provides Java SDK V2.0 examples for creating, updating, deleting, and querying pipelines.
Prerequisites
Complete Initialization before you proceed.
Create a pipeline
Call the AddPipeline operation to create a pipeline.
-
Pipeline type selection is covered in Create a pipeline.
-
If you receive the 'The resource "Pipeline" quota has been used up' error, your pipeline quota is exhausted. To request an increase, submit a ticket.
-
NotifyConfig settings for pipeline messages are covered in NotifyConfig details.
-
Pipelines support queue and topic mode message configurations. Configure message notifications.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Use an AccessKey pair to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.AddPipelineRequest addPipelineRequest = new com.aliyun.mts20140618.models.AddPipelineRequest()
// The pipeline name.
.setName("test-pipeline")
// The pipeline type.
.setSpeed("Standard")
// The pipeline speed level.
.setSpeedLevel(1L)
// The Message Service (MNS) notification configuration.
.setNotifyConfig("{\"Topic\":\"mts-topic-1\"}")
// The role.
.setRole("AliyunMTSDefaultRole");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// To run the code, copy it and print the API return value.
client.addPipelineWithOptions(addPipelineRequest, runtime);
} catch (TeaException error) {
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Update a pipeline configuration
Call the UpdatePipeline operation to update a pipeline configuration.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Use an AccessKey pair to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.UpdatePipelineRequest updatePipelineRequest = new com.aliyun.mts20140618.models.UpdatePipelineRequest()
// The ID of the pipeline to update.
.setPipelineId("d1ce4d3efcb549419193f50f1fcd****")
// The new pipeline name.
.setName("example-pipeline-****")
// The new pipeline state.
.setState("Paused")
// The Message Service (MNS) configuration.
.setNotifyConfig("{\"Topic\":\"example-topic-****\"}")
// The role associated with the current RAM user.
.setRole("AliyunMTSDefaultRole");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// To run the code, copy it and print the API return value.
client.updatePipelineWithOptions(updatePipelineRequest, runtime);
} catch (TeaException error) {
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Delete a pipeline
Call the DeletePipeline operation to delete a pipeline.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Use an AccessKey pair to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.DeletePipelineRequest deletePipelineRequest = new com.aliyun.mts20140618.models.DeletePipelineRequest()
// The ID of the pipeline to delete.
.setPipelineId("d1ce4d3efcb549419193f50f1fcd****");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// To run the code, copy it and print the API return value.
client.deletePipelineWithOptions(deletePipelineRequest, runtime);
} catch (TeaException error) {
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Query pipelines by ID
Call the QueryPipelineList operation to query pipelines by ID.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Use an AccessKey pair to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.QueryPipelineListRequest queryPipelineListRequest = new com.aliyun.mts20140618.models.QueryPipelineListRequest()
// The IDs of the pipelines to query.
.setPipelineIds("d1ce4d3efcb549419193f50f1fcd****,72dfa5e679ab4be9a3ed9974c736****");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// To run the code, copy it and print the API return value.
client.queryPipelineListWithOptions(queryPipelineListRequest, runtime);
} catch (TeaException error) {
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Query pipelines by state
Call the SearchPipeline operation to query pipelines by state.
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Use an AccessKey pair to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Set the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.SearchPipelineRequest searchPipelineRequest = new com.aliyun.mts20140618.models.SearchPipelineRequest()
// The state of the pipelines to search for.
.setState("Paused")
// The number of entries per page for a paged query.
.setPageSize(10L)
// The page number.
.setPageNumber(1L);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// To run the code, copy it and print the API return value.
client.searchPipelineWithOptions(searchPipelineRequest, runtime);
} catch (TeaException error) {
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// This is for demonstration only. Handle exceptions with care and do not ignore them in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis URL
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}