Note:

Consume a private OCI Streaming topic behind an API Gateway using OCI REST API call

Introduction

The Oracle Cloud Infrastructure (OCI) Streaming service provides a fully managed, scalable, and durable solution for ingesting and consuming high-volume data streams in real-time. Use OCI Streaming for any use case in which data is produced and processed continually and sequentially in a publish-subscribe messaging model.

In this scenario, we need to expose and consume a private OCI Streaming topic using a public API Gateway to control and secure the access.

Objective

This tutorial demonstrates how to consume OCI Streaming topic using API Gateway REST API calls.

Prerequisites

Task 1: Get details from your OCI Streaming

  1. Go to your stream and note the OCID, click Analytics & AI under Messaging, click Streaming and select your stream.

  2. Note the OCID and Message Endpoint, you’re going to need it for your API Gateway.

    T1_2

Task 2: Create a public API Gateway

Task 3: Create a deployment for your API Gateway

  1. Select the API Gateway created in Task 2, click Deployments, and then click Create Deployment.

  2. Now, create the prefix by replacing your_ocid_for_stream with your stream OCID below, fill the name as publicTopic.

    /20180418/streams/your_ocid_for_stream
    

    T3_1

  3. Click Next.

    T3_2

  4. Click Next.

  5. Creating Route 1 for groupCursors: Create the URL using the endpoint and stream OCID you’ve gathered in Task 2 of this tutorial and build your URL.

    <streaming_endpoint>/20180418/streams/<stream_ocid>/groupCursors
    

    Note: To consume the stream, the OCI REST API for Streaming uses two endpoints groupCursors and messages, you need to create those two routes. Now provide the needed information such as Path, Methods, Backend type as below:

    T3_2

  6. Click +Another route and add Route 2 for messages: Using the same URL but with the different endpoint at the end as /messages.

    T3_2

  7. Go to your publicTopic and note the API Gateway endpoint.

    T3_2

Task 4: Generate test messages on your streaming

Task 5: Consume OCI Streaming via REST API behind the API Gateway

  1. Download the sample Python consume code consume_rest_api_oci_lab.py.

  2. Change the values for your API Gateway endpoint and stream OCID as indicated with the values you gathered earlier in this tutorial.

    T4_1

  3. Run your Python code to verify it’s working.

    python3 consume_rest_api_oci_lab.py
    

    T4_2

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.