Collegamento e configurazione di criteri nell'interfaccia utente

Questa pagina si applica ad Apigee e Apigee hybrid.

Visualizza la documentazione di Apigee Edge.

L'aggiunta di funzionalità basate su criteri a un proxy API è un processo in due fasi:

  1. Configurare un'istanza di un tipo di criterio.
  2. Collega l'istanza del criterio a un Flow.

Il diagramma seguente mostra la relazione tra criteri e flussi. Come puoi vedere, un criterio è associato a un flusso come passaggio di elaborazione. Per configurare il comportamento desiderato per l'API, devi avere maggiori informazioni sui flussi. (questo argomento è stato trattato in precedenza nella sezione Configurare i flussi.

Relazione tra politiche e flussi

Un tipo di criterio di uso comune è il criterio SpikeArrest. SpikeArrest impedisce gli aumenti improvvisi del traffico dei messaggi che potrebbero riempire i servizi di backend.

Collegamento di un criterio a un flusso

Nuovo editor proxy

Per collegare un criterio a un flusso:

  1. Seleziona un proxy API e vai alla visualizzazione Develop.
  2. Nel riquadro a sinistra, fai clic sul pulsante + nella riga Norme.
  3. Nella finestra di dialogo Crea criterio, fai clic sul campo Seleziona il tipo di criterio, scorri verso il basso fino a Gestione del traffico e seleziona SpikeArrest.

  4. Se vuoi, puoi modificare il Nome visualizzato e il Nome del criterio.

    Finestra di dialogo Crea criterio.

    Al termine, fai clic su Crea per creare il criterio.

  5. Ora che hai creato il criterio Spike Arrest, puoi collegarlo a un passaggio nel PreFlow. Per farlo, seleziona Endpoint proxy > default > PreFlow nel riquadro a sinistra:

    Endpoint di destinazione per la selezione PreFlow in Proxy Explorer.

  6. Fai clic sul pulsante + accanto a PreFlow nel riquadro Risposta in basso a destra nell'Editor visivo:

    Fai clic sul pulsante + accanto a PreFlow nel riquadro Risposta.

  7. Nella finestra di dialogo Aggiungi passaggio del criterio, seleziona il criterio Arresto di picche.
  8. Fai clic su Aggiungi per allegare il criterio.

    Il criterio Spike Arrest è ora visualizzato nel riquadro Response (Risposta):

    Criterio di arresto con picco visualizzato nel riquadro Risposta.

    Il seguente codice XML per il proxy viene visualizzato nell'editor di testo:

    <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>

Puoi configurare un criterio modificando direttamente la configurazione XML nella visualizzazione Codice. Ad esempio, la frequenza massima di messaggi per il criterio Spike Arrest è inizialmente impostata su 30 messaggi al secondo. Puoi modificare la frequenza di picco modificando il valore dell'elemento <Rate> nel file XML del criterio. Per ulteriori dettagli sulla configurazione dei criteri, consulta la documentazione di riferimento sui criteri.

Puoi anche tagliare e incollare i criteri nella visualizzazione Codice. Questo è un ottimo modo per riutilizzare i criteri degli esempi disponibili su GitHub.

Quando apporti modifiche a una definizione di norma nella vista Codice, le modifiche vengono applicate anche nel Controllo proprietà. È vero anche il contrario: apporta le modifiche nel Controllo proprietà e queste vengono visualizzate nel file XML nella vista Codice.

Per la documentazione specifica per i criteri per le quote utilizzati in questo argomento, consulta Criteri per le quote.