All Products
Search
Document Center

Realtime Compute for Apache Flink:Flink Java SDK

Last Updated:Jun 22, 2026

Topik ini menjelaskan cara menginstal dan menggunakan Realtime Compute for Apache Flink Java SDK.

Catatan penggunaan

Dari 19 September hingga 27 Oktober 2022, Alibaba Cloud meluncurkan pembaruan SDK untuk Realtime Compute for Apache Flink di semua wilayah. Versi baru ini kini menjadi versi default.

Catatan

Prasyarat

  • AccessKey telah dibuat. Untuk informasi selengkapnya, lihat Buat AccessKey.

    Catatan

    Untuk meminimalkan risiko keamanan jika AccessKey Akun Alibaba Cloud Anda bocor, kami menyarankan Anda membuat Pengguna RAM, memberikan izin terkait Flink, lalu menggunakan AccessKey-nya untuk memanggil SDK. Untuk informasi selengkapnya, lihat topik berikut:

  • Java 8 atau yang lebih baru telah diinstal.

  • Akun Anda memiliki izin yang diperlukan. Untuk informasi selengkapnya, lihat Manajemen Izin.

Realtime Compute for Apache Flink Java SDKs

Selling console

Metode instalasi

Kode

Apache Maven

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>foasconsole20211028</artifactId>

<version>2.1.0</version>

</dependency>

Gradle Groovy DSL

implementation 'com.aliyun:foasconsole20211028:2.1.0'

Gradle Kotlin DSL

implementation("com.aliyun:foasconsole20211028:2.1.0")

Scala SBT

libraryDependencies += "com.aliyun" % "foasconsole20211028" % "2.1.0"

Apache Ivy

<dependency org="com.aliyun" name="foasconsole20211028" rev="2.1.0" />

Groovy Grape

@Grapes(

@Grab(group='com.aliyun', module='foasconsole20211028', version='2.1.0')

)

Leiningen

[com.aliyun/foasconsole20211028 "2.1.0"]

Apache Buildr

'com.aliyun:foasconsole20211028:jar:2.1.0'

Development console

Metode instalasi

Kode

Apache Maven

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>ververica20220718</artifactId>

<version>1.7.0</version>

</dependency>

Gradle Groovy DSL

implementation 'com.aliyun:ververica20220718:1.7.0'

Gradle Kotlin DSL

implementation("com.aliyun:ververica20220718:1.7.0")

Scala SBT

libraryDependencies += "com.aliyun" % "ververica20220718" % "1.7.0"

Apache Ivy

<dependency org="com.aliyun" name="ververica20220718" rev="1.7.0" />

Groovy Grape

@Grapes(

@Grab(group='com.aliyun', module='ververica20220718', version='1.7.0')

)

Leiningen

[com.aliyun/ververica20220718 "1.7.0"]

Apache Buildr

'com.aliyun:ververica20220718:jar:1.7.0'

Debug online dan hasilkan contoh SDK

Anda dapat menggunakan OpenAPI Explorer untuk memanggil operasi API secara online, menghasilkan kode contoh SDK secara dinamis, dan mencari operasi API dengan cepat. Anda dapat melihat dan mengunduh kode contoh SDK untuk operasi API di halaman Realtime Compute for Apache Flink dan Realtime Compute Selling Console. Untuk informasi selengkapnya, lihat Memulai Cepat.

Pada tab SDK Example, pilih bahasa, seperti Java, klik Run Example untuk menjalankan kode secara online, atau klik Download Complete Project untuk mengunduh kode contoh.

Contoh

Catatan
  • Untuk titik akhir Realtime Compute for Apache Flink selling console, lihat Endpoints.

  • Untuk titik akhir Realtime Compute for Apache Flink development console, lihat Endpoints.

Ruang kerja yang telah dibeli

Contoh ini menunjukkan cara mengambil detail ruang kerja Realtime Compute for Apache Flink yang telah dibeli di wilayah tertentu.

Region: ID wilayah. Untuk informasi selengkapnya, lihat Endpoints. Misalnya, cn-hangzhou.

package com.aliyun.sample;
import com.aliyun.foasconsole20211028.models.DescribeInstancesResponse;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.foasconsole20211028.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "foasconsole.aliyuncs.com";
        return new com.aliyun.foasconsole20211028.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        com.aliyun.foasconsole20211028.Client client = Sample.createClient();
        com.aliyun.foasconsole20211028.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.foasconsole20211028.models.DescribeInstancesRequest()
                .setRegion("cn-beijing");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            DescribeInstancesResponse response = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
            System.out.println(response.statusCode);
            // Kueri ID wilayah instans.
            System.out.println(response.getBody().getInstances().get(0).zoneId);
            // Kueri ID kelompok sumber daya tempat instans berada.
            System.out.println(response.getBody().getInstances().get(0).resourceGroupId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Buat penyebaran

Penyebaran SQL

Contoh ini menunjukkan cara membuat penyebaran SQL.

  • workspace: ID ruang kerja. Anda dapat memperoleh ID ini dari ResourceId yang dikembalikan saat Anda melihat ruang kerja yang telah dibeli. Misalnya, adf9e514****.

  • namespace: Nama namespace. Misalnya, test-default.

  • body.name: Nama pekerjaan. Misalnya, mysql_data_holo_test.

  • body.engineVersion: Versi engine. Misalnya, vvr-8.0.7-flink-1.17. Anda dapat memperoleh versi engine yang didukung dengan menampilkan daftar versi engine yang didukung.

  • body.sqlArtifact.sqlScript: Konten skrip SQL. Contoh: CREATE TEMPORARY TABLE datagen_source( name VARCHAR ) WITH ( 'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink( name VARCHAR ) with ( 'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;.

  • body.sqlArtifact.kind: Jenis pekerjaan. Misalnya, SQLSCRIPT.

  • body.deploymentTarget.mode: Mode penyebaran. Hanya mode PER_JOB yang didukung.

  • body.deploymentTarget.name: Nama antrian penyebaran. Misalnya, default-queue.

  • body.executionMode: Mode eksekusi. Misalnya, STREAMING (mode streaming).

  • body.streamingResourceSetting.resourceSettingMode: Mode sumber daya untuk mode streaming. Misalnya, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: Jumlah core CPU untuk JobManager. Misalnya, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: Memori JobManager. Misalnya, 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: Jumlah core CPU TaskManager. Misalnya, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: Memori TaskManager. Misalnya, 4.0 GiB.

package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.teaopenapi.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-beijing.aliyuncs.com";
        return new com.aliyun.teaopenapi.Client(config);
    }
    /**
     * description :
     * <p>Parameter API</p>
     *
     * @param path params
     * @return OpenApi.Params
     */
    public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
        com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
                // Nama operasi API.
                .setAction("CreateDeployment")
                // Versi operasi API.
                .setVersion("2022-07-18")
                // Protokol operasi API.
                .setProtocol("HTTPS")
                // Metode HTTP operasi API.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // Jalur permintaan operasi API.
                .setPathname("/api/v2/namespaces/" + namespace + "/deployments")
                // Format badan permintaan.
                .setReqBodyType("json")
                // Format badan respons.
                .setBodyType("json");
        return params;
    }
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.teaopenapi.Client client = Sample.createClient();
        com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("test-default");
        // parameter body
        java.util.Map<String, Object> body = TeaConverter.buildMap(
                new TeaPair("name", "mysql_data_holo_test"),
                new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
                new TeaPair("artifact", TeaConverter.buildMap(
                        new TeaPair("sqlArtifact", TeaConverter.buildMap(
                                new TeaPair("sqlScript", "CREATE TEMPORARY TABLE datagen_source(   name VARCHAR ) WITH (   'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink(   name  VARCHAR ) with (   'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;")
                        )),
                        new TeaPair("kind", "SQLSCRIPT")
                )),
                new TeaPair("deploymentTarget", TeaConverter.buildMap(
                        new TeaPair("mode", "PER_JOB"),
                        new TeaPair("name", "default-queue")
                )),
                new TeaPair("executionMode", "STREAMING"),
                new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
                        new TeaPair("resourceSettingMode", "BASIC"),
                        new TeaPair("basicResourceSetting", TeaConverter.buildMap(
                                new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                )),
                                new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                ))
                        ))
                ))
        );
        // parameter header
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        headers.put("workspace", "ab2*******884d");
        // opsi runtime
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
                .setHeaders(headers)
                .setBody(body);
        // Metode ini mengembalikan Map. Anda dapat memperoleh badan respons, header respons, dan kode status HTTP dari map tersebut.
        client.callApi(params, request, runtime);
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

Penyebaran JAR

Contoh ini menunjukkan cara membuat penyebaran JAR.

Catatan
  • Unggah paket JAR ke Bucket OSS dan pastikan ruang kerja Realtime Compute for Apache Flink Anda memiliki izin untuk mengaksesnya. Untuk informasi selengkapnya, lihat Unggahan sederhana.

  • Setelah file diunggah, URL unduhan berformat https://<Bucket>.oss-<Region>.aliyuncs.com/<NamaFile>.

  • workspace: ID ruang kerja. Anda dapat memperoleh ID ini dari ResourceId yang dikembalikan saat Anda melihat ruang kerja yang telah dibeli. Misalnya, adf9e514****.

  • namespace: Nama namespace. Misalnya, test-default.

  • body.name: Nama pekerjaan. Misalnya, my-test-jar.

  • body.engineVersion: Versi engine. Misalnya, vvr-8.0.7-flink-1.17. Anda dapat memperoleh daftar versi engine yang didukung.

  • body.jarArtifact.kind: Jenis artefak pekerjaan. Misalnya, JAR.

  • body.jarArtifact.jarUri: Jalur URL lengkap penyebaran JAR. Misalnya, https://myBucket/oss-cn-hangzhou/test.jar.

  • body.jarArtifact.entryClass: Kelas titik masuk. Anda harus menentukan nama kelas lengkap. Misalnya, org.apache.flink.test.

  • body.deploymentTarget.mode: Mode penyebaran. Hanya mode PER_JOB yang didukung.

  • body.deploymentTarget.name: Nama antrian penyebaran. Misalnya, default-queue.

  • body.executionMode: Mode eksekusi. Misalnya, STREAMING (mode streaming).

  • body.streamingResourceSetting.resourceSettingMode: Mode sumber daya untuk mode streaming. Misalnya, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: Jumlah core CPU untuk JobManager. Misalnya, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: Memori JobManager. Misalnya, 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: Jumlah core CPU untuk TM. Misalnya, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: Memori TaskManager. Misalnya, 4.0 GiB.

package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.teaopenapi.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.teaopenapi.Client(config);
    }
    /**
     * description :
     * <p>Parameter API</p>
     *
     * @param path params
     * @return OpenApi.Params
     */
    public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
        com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
                // Nama operasi API.
                .setAction("CreateDeployment")
                // Versi operasi API.
                .setVersion("2022-07-18")
                // Protokol operasi API.
                .setProtocol("HTTPS")
                // Metode HTTP operasi API.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // Jalur permintaan operasi API.
                .setPathname("/api/v2/namespaces/" + namespace + "/deployments")
                // Format badan permintaan.
                .setReqBodyType("json")
                // Format badan respons.
                .setBodyType("json");
        return params;
    }
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.teaopenapi.Client client = Sample.createClient();
        com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("flink-default");
        // parameter body
        java.util.Map<String, Object> body = TeaConverter.buildMap(
                new TeaPair("name", "my-test-jar"),
                new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
                new TeaPair("artifact", TeaConverter.buildMap(
                        new TeaPair("kind", "JAR"),
                        new TeaPair("jarArtifact", TeaConverter.buildMap(
                                new TeaPair("jarUri", "https://flink-test.oss-cn-hangzhou.aliyuncs.com/flinkDemo.jar?*****"),
                                new TeaPair("entryClass", "com.aliyun.FlinkDemo")
                        ))
                )),
                new TeaPair("deploymentTarget", TeaConverter.buildMap(
                        new TeaPair("mode", "PER_JOB"),
                        new TeaPair("name", "default-queue")
                )),
                new TeaPair("executionMode", "STREAMING"),
                new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
                        new TeaPair("resourceSettingMode", "BASIC"),
                        new TeaPair("basicResourceSetting", TeaConverter.buildMap(
                                new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                )),
                                new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                ))
                        ))
                ))
        );
        // parameter header
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        headers.put("workspace", "d05a*****e44");
        // opsi runtime
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
                .setHeaders(headers)
                .setBody(body);
        // Metode ini mengembalikan Map. Anda dapat memperoleh badan respons, header respons, dan kode status HTTP dari map tersebut.
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

Daftar penyebaran

Contoh ini menunjukkan cara menampilkan semua penyebaran dalam namespace.

  • workspace: ID ruang kerja. Anda dapat memperoleh ID dari ResourceId yang dikembalikan oleh operasi di Lihat ruang kerja yang telah dibeli. Misalnya, adf9e514****.

  • namespace: Nama namespace. Misalnya, test-default.

package com.sample;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;
import com.aliyun.ververica20220718.models.ListDeploymentsResponse;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.ListDeploymentsHeaders listDeploymentsHeaders = new com.aliyun.ververica20220718.models.ListDeploymentsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.ListDeploymentsRequest listDeploymentsRequest = new com.aliyun.ververica20220718.models.ListDeploymentsRequest();
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            ListDeploymentsResponse response=client.listDeploymentsWithOptions("test-default", listDeploymentsRequest, listDeploymentsHeaders, runtime);
            System.out.println(response.body.data.get(0).name);
            System.out.println(response.body.data.get(0).deploymentId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Jalankan pekerjaan

Contoh ini menunjukkan cara menjalankan pekerjaan dari penyebaran dalam namespace.

  • workspace: ID ruang kerja. Misalnya, adf9e5147a****.

  • namespace: Nama namespace, seperti test-default.

  • deploymentId: ID penyebaran. Anda dapat memperoleh ID ini dengan memanggil operasi Daftar penyebaran. Misalnya, 10283a02-c6a6-4f3e-9f93-8dab****.

  • kind: Jenis strategi pemulihan. Nilai yang didukung adalah NONE (jalankan tanpa status), LATEST_SAVEPOINT (jalankan dari titik simpan terbaru), FROM_SAVEPOINT (jalankan dari titik simpan tertentu), dan LATEST_STATE (jalankan dari status terbaru).

package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StartJobWithParamsResponse;
import com.alibaba.fastjson2.JSON;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.StartJobWithParamsHeaders startJobWithParamsHeaders = new com.aliyun.ververica20220718.models.StartJobWithParamsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.DeploymentRestoreStrategy jobStartParametersDeploymentRestoreStrategy = new com.aliyun.ververica20220718.models.DeploymentRestoreStrategy()
                .setKind("NONE");
        com.aliyun.ververica20220718.models.JobStartParameters jobStartParameters = new com.aliyun.ververica20220718.models.JobStartParameters()
                .setRestoreStrategy(jobStartParametersDeploymentRestoreStrategy)
                .setDeploymentId("10283a02-**--**-8dabf617d52f");
        com.aliyun.ververica20220718.models.StartJobWithParamsRequest startJobWithParamsRequest = new com.aliyun.ververica20220718.models.StartJobWithParamsRequest()
                .setBody(jobStartParameters);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            StartJobWithParamsResponse response = client.startJobWithParamsWithOptions("test-default", startJobWithParamsRequest, startJobWithParamsHeaders, runtime);
            System.out.println(JSON.toJSON(response.body));
        } catch (TeaException error) {
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Daftar pekerjaan

Contoh ini menunjukkan cara mengkueri semua pekerjaan untuk penyebaran tertentu.

  • workspace: ID ruang kerja. Misalnya, adf9e5147****.

  • namespace: Nama namespace, misalnya, test-default.

  • deploymentId: ID penyebaran. Untuk memperoleh ID ini, lihat Dapatkan daftar penyebaran. Misalnya, 8489b7ec-**--**-cc4c17fa12b0.

package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.ListJobsResponse;
import com.alibaba.fastjson2.JSON;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-beijing.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.ListJobsHeaders listJobsHeaders = new com.aliyun.ververica20220718.models.ListJobsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.ListJobsRequest listJobsRequest = new com.aliyun.ververica20220718.models.ListJobsRequest()
                .setDeploymentId("8489b7ec-****-****-****-cc4c17fa12b0");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            ListJobsResponse response =  client.listJobsWithOptions("test-default", listJobsRequest, listJobsHeaders, runtime);
            // Lihat hasil eksekusi pekerjaan.
            System.out.println("Hasil eksekusi adalah: "+response.body.success);
            // Peroleh ID pekerjaan. ID ini digunakan untuk membatalkan pekerjaan.
            System.out.println(response.body.getData().get(0).jobId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Hentikan pekerjaan

Contoh ini menunjukkan cara menghentikan pekerjaan.

  • workspace: ID ruang kerja. Misalnya, adf9e5147****.

  • namespace: Nama namespace, misalnya, test-default.

  • jobId: ID pekerjaan. Untuk informasi selengkapnya, lihat Peroleh informasi tentang penyebaran tertentu. Misalnya, 3171d4d1-****-****-****-e762493b7765.

  • stopStrategy: Strategi penghentian pekerjaan. Nilai yang didukung adalah NONE (hentikan pekerjaan langsung), STOP_WITH_SAVEPOINT (hentikan pekerjaan setelah titik simpan dibuat), dan STOP_WITH_DRAIN (hentikan pekerjaan dalam mode drain).

package com.aliyun.sample;
import com.alibaba.fastjson2.JSON;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StopJobResponse;
public class Sample {
    /**
     * description :
     * <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // Menyematkan pasangan AccessKey secara langsung dalam kode dapat menyebabkan kebocoran pasangan AccessKey dan mengancam keamanan semua sumber daya dalam akun Anda. Kode contoh berikut hanya untuk referensi.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID telah disetel di lingkungan runtime Anda.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET telah disetel di lingkungan runtime Anda.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.StopJobHeaders stopJobHeaders = new com.aliyun.ververica20220718.models.StopJobHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.StopJobRequestBody stopJobRequestBody = new com.aliyun.ververica20220718.models.StopJobRequestBody()
                .setStopStrategy("NONE");
        com.aliyun.ververica20220718.models.StopJobRequest stopJobRequest = new com.aliyun.ververica20220718.models.StopJobRequest()
                .setBody(stopJobRequestBody);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            StopJobResponse response = client.stopJobWithOptions("test-default", "7970e881-****-****-****-1a3746710878", stopJobRequest, stopJobHeaders, runtime);
            System.out.println(JSON.toJSON(response.getBody().getData()));
        } catch (TeaException error) {
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Dalam contoh ini, pesan error dicetak hanya sebagai referensi. Kami menyarankan agar Anda menangani exception dengan hati-hati dalam proyek Anda dan tidak mengabaikannya.
            // Pesan error
            System.out.println(error.getMessage());
            // Alamat diagnostik
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Referensi

Untuk informasi selengkapnya mengenai Python SDK, lihat Referensi Python SDK.