Melampirkan dan mengonfigurasi kebijakan di UI

Halaman ini berlaku untuk Apigee dan Apigee Hybrid.

Baca dokumentasi Apigee Edge.

Menambahkan kemampuan berbasis kebijakan ke proxy API adalah proses dua langkah:

  1. Konfigurasikan instance jenis kebijakan.
  2. Melampirkan instance kebijakan ke Flow.

Diagram di bawah menunjukkan hubungan antara kebijakan dan alur. Seperti yang dapat Anda lihat, kebijakan disertakan ke flow sebagai langkah pemrosesan. Guna mengonfigurasi perilaku yang diinginkan untuk API, Anda perlu memahami sedikit tentang alur. (Topik ini telah dibahas sebelumnya dalam Mengonfigurasi flow.)

Hubungan antara kebijakan dan alur

Salah satu jenis kebijakan yang umum digunakan adalah kebijakanSpikeArrest. SpikeArrest mencegah peningkatan traffic pesan yang tiba-tiba yang mungkin membanjiri layanan backend Anda.

Melampirkan kebijakan ke flow

Editor Proxy Baru

Untuk melampirkan kebijakan ke flow:

  1. Pilih proxy API, lalu buka tampilan Develop.
  2. Di panel kiri, klik tombol + di baris Policies.
  3. Pada dialog Create policy, klik kolom Select policy type, lalu scroll ke bawah ke Traffic Management, lalu pilih SpikeArrest.

  4. Jika ingin, Anda dapat mengubah Nama tampilan dan Nama kebijakan.

    Dialog "Create policy".

    Setelah selesai, klik Buat untuk membuat kebijakan.

  5. Setelah membuat kebijakan Spike Arrest, Anda dapat melampirkannya ke langkah di PreFlow. Untuk melakukannya, pilih Proxy Endpoints > default > PreFlow di panel sebelah kiri:

    Endpoint target untuk pemilihan PreFlow di Proxy Explorer.

  6. Klik tombol + di samping PreFlow di panel Response di kanan bawah Visual Editor:

    Klik tombol + di samping PreFlow di panel Response.

  7. Pada dialog Add policy step, pilih kebijakan Spike Arrest.
  8. Klik Add untuk melampirkan kebijakan.

    Kebijakan Spike Arrest kini ditampilkan di panel Response:

    Kebijakan Penangkapan Lonjakan ditampilkan di panel Respons.

    Kode XML untuk proxy berikut ditampilkan di editor teks:

    <ProxyEndpoint name="default">
      <PreFlow name="PreFlow">
        <Request/>
        <Response>
          <Step><
            <Name>SA-</Name>
          </Step>
        </Response>
      </PreFlow>
      <Flows/>
      <PostFlow name="PostFlow">
        <Request/>
        <Response/>
      </PostFlow>
      <HTTPProxyConnection>
        <BasePath>/myproxy</BasePath>
      </HTTPProxyConnection>
      <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
      </RouteRule>
    </ProxyEndpoint>
      

Detaching policies from a flow

To detach a policy from a flow, click the three-dot menu next to the flow and select Delete policy step

Classic Proxy Editor

To attach a policy to a flow:

  1. Select an API proxy and navigate to the Develop view.
  2. In the API Proxy Editor, select the flow to which you want to attach a policy in the Navigator pane.
    For example, the PreFlow flow is selected for the default API proxy endpoint in the following figure:
    Select flow to which you want to attach policy
  3. In the Design view, click +Step associated with the request or response flow to attach a policy. For example:
    Click +Step
    The Add Step dialog opens displaying a categorized list of policies.
    List of policies in categories
  4. Scroll and select the policy type that you want to attach to the selected flow.
  5. Modify the following fields.
    • Display Name: Unique display name for the policy. The UI will generate a default name, but it is advisable to create a descriptive name for the policy. This will ensure that other developers in your organization have an easy time understanding what the policy is intended to do.

    • Name: Unique name for the policy. The policy name matches the display name with the following exceptions:

      • Spaces are replaced by dashes.

      • Consecutive dashes are replaced by a single dash.

      • Except for dashes, underscores, and spaces (which are replaced, as noted above), characters that are not alphanumeric, such as pound signs, percent signs, ampersands, and so on, are removed.

  6. Click Add.

    The policy is attached to the selected flow.

After the policy is attached, you’ll see the policy displayed in the Designer view for the flow, in this example the PreFlow of the default proxy endpoint, and in the Policies list in the Navigation pane. The Code view, which displays the XML for the newly attached policy, displays below the Designer view. Apigee generates an instance of the policy that contains a set of reasonable default values.

Policies in the PreFlow in the Designer and Code view

Adding a policy without attaching it to a flow

To add a policy without attaching it to a flow, which is useful for Handling faults, click + in the Policies bar in the Navigator view to open the Add Policy dialog and add the policy (as described in steps 4 through 6 in the previous section).

Click + to add policy

A policy that is not attached to any flow is flagged with the detached icon in the Policies list, as shown adjacent to the API key message policy shown in the previous figure.

After you create the policy, you can attach it to a flow by dragging and dropping it from the Policies list to the desired flow in the Designer view.

Detaching policies from a flow

To detach a policy from a Flow, select the Flow. Mouse over the icon for the policy in the Designer view of the Flow. Click the X in the circle that appears in the icon.

Deleting a policy instance

To delete a policy instance, mouse over the entry for the policy in the Navigator view. Click the X in the circle that appears to the right of the entry.

Configuring policies in the UI

When the UI generates a policy instance, it applies reasonable default values for common settings. You may need to modify these settings to meet your requirements.

For example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SpikeArrest async="false" continueOnError="false" enabled="true" name="spikearrest-1">
  <DisplayName>SpikeArrest-1</DisplayName>
  <FaultRules/>
  <Properties/>
  <Identifier ref="request.header.some-header-name"/>
  <MessageWeight ref="request.header.weight"/>
  <Rate>30ps</Rate>
</SpikeArrest>

Anda dapat mengonfigurasi kebijakan dengan langsung mengedit konfigurasi XML-nya dalam tampilan Code. Misalnya, kecepatan pesan puncak untuk kebijakan Penangkapan Spike awalnya ditetapkan ke 30 pesan per detik. Anda dapat mengubah frekuensi puncak dengan mengubah nilai elemen <Rate> dalam XML untuk kebijakan tersebut. Untuk detail lebih lanjut tentang cara mengonfigurasi kebijakan, lihat Referensi kebijakan.

Anda juga dapat memotong dan menempelkan kebijakan ke tampilan Kode. Ini adalah cara yang tepat untuk menggunakan kembali kebijakan dari contoh yang tersedia di GitHub.

Saat Anda membuat perubahan pada definisi kebijakan di tampilan Code, perubahan tersebut akan tercermin di Property Inspector. Hal sebaliknya juga berlaku — buat perubahan di Property Inspector dan perubahan akan muncul di XML di tampilan Code.

Untuk dokumentasi khusus tentang kebijakan Kuota yang digunakan dalam topik ini, lihat Kebijakan kuota.