Adjuntar y configurar políticas en la interfaz de usuario

Esta página se aplica a Apigee y Apigee híbrido .

Ver la documentación de Apigee Edge .

Agregar capacidades basadas en políticas a un proxy API es un proceso de dos pasos:

  1. Configurar una instancia de un tipo de política.
  2. Adjunte la instancia de política a un flujo.

El diagrama a continuación muestra la relación entre políticas y flujos. Como puede ver, una política se asocia a un flujo como paso de procesamiento. Para configurar el comportamiento deseado para su API, necesita comprender algunos aspectos de los flujos. (Este tema se trató anteriormente en Configuración de flujos ).

Relación entre políticas y flujos

Un tipo de política comúnmente utilizada es la política SpikeArrest . SpikeArrest evita aumentos repentinos en el tráfico de mensajes que podrían saturar los servicios de backend.

Adjuntar una política a un flujo

Nuevo editor de proxy

Para adjuntar una política a un flujo:

  1. Seleccione un proxy API y navegue hasta la vista Desarrollar .
  2. En el panel izquierdo, haga clic en el botón + en la fila Políticas .
  3. En el cuadro de diálogo Crear política , haga clic en el campo Seleccionar tipo de política y desplácese hacia abajo hasta Administración de tráfico y seleccione SpikeArrest .

  4. Opcionalmente, puede cambiar el nombre para mostrar y el nombre de la política.

    Crear diálogo de política.

    Cuando haya terminado, haga clic en Crear para crear la política.

  5. Ahora que ha creado la política de detención de picos , puede asociarla a un paso del PreFlow. Para ello, seleccione Puntos finales de proxy > predeterminado > PreFlow en el panel izquierdo:

    Puntos finales de destino para la selección de PreFlow en el Explorador de proxy.

  6. Haga clic en el botón + junto a PreFlow en el panel Respuesta en la parte inferior derecha del Editor visual:

    Haga clic en el botón + junto a PreFlow en el panel Respuesta.

  7. En el cuadro de diálogo Agregar paso de política , seleccione la política Spike Arrest .
  8. Haga clic en Agregar para adjuntar la política.

    La política de detención de picos ahora se muestra en el panel de Respuesta :

    La política de detención de picos se muestra en el panel de Respuesta.

    El siguiente código XML para el proxy se muestra en el editor de texto:

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

Puede configurar una política editando directamente su configuración XML en la vista Código . Por ejemplo, la tasa máxima de mensajes para la política "Detención de picos" está establecida inicialmente en 30 mensajes por segundo. Puede cambiar esta tasa modificando el valor del elemento Rate en el XML de la política. Para obtener más información sobre la configuración de políticas, consulte la Referencia de políticas .

También puedes copiar y pegar políticas en la vista de Código . Esta es una excelente manera de reutilizar políticas de los ejemplos disponibles en GitHub.

Al realizar cambios en una definición de política en la vista de Código , estos se reflejan en el Inspector de Propiedades . Lo contrario también es cierto: al realizar cambios en el Inspector de Propiedades , estos aparecen en el XML de la vista de Código .

Para obtener documentación específica de la política de cuotas utilizada en este tema, consulte Política de cuotas .

Utilice el código Gemini Assist para explicar las políticas

Si tiene Gemini Code Assist , puede usarlo para comprender políticas y elementos de políticas directamente en la interfaz de usuario de Apigee en la consola Cloud :

  • Al editar la política en la vista Código , resalte parte del código, como un elemento o atributo XML. También puede resaltar varios elementos.
  • Haga clic en el icono de Gemini Code Assist, como se muestra a continuación. El panel lateral muestra información sobre la política y el elemento seleccionado.

Explicación del código de asistencia de Gemini Code