1. StreamNative Cloud
  2. Quick start

Quick start - StreamNative Cloud

Before you begin

This quick start assumes you are familiar with the basics of Apache Pulsar. To review Apache Pulsar concepts, see the Concepts section. This quick start also assumes you do not have a StreamNative Cloud account yet.

Sign up

Note

If you have an email account configured for using Single Sign-On (SSO) with StreamNative Cloud, use that email address and password in the steps below.

To sign up, navigate to the StreamNative Cloud Console login page. Follow the prompts to create an account. You might have to wait briefly for your first organization to be created. After your new organization is created, you can create your first instance and cluster.

Create an instance and cluster

This section explains how to create a free cluster. For details about how to create a standard cluster, see create a cluster through StreamNative Cloud Console.

  1. Click the name of your first organization. In the figure below, the organization name is org-2.

    image of organization section

  2. On the Create a free dev instance section, select your deployment region, and click Create Free Instance.

It can take up to 10 minutes for your instance and cluster to be created. When the instance and cluster creation processes are complete, continue on to creating a tenant.

Create a tenant

  1. On the left navigation pane, under Tenant/Namespace, select the current default tenant/namespace, and then click New Tenant.

  2. On the Tenants page, click New Tenant.

  3. Configure the tenant and then click Confirm. You must enter a name for the tenant and specify the allowed cluster. You can optionally add Admin Roles.

    • Tenant enter a name for the tenant. A tenant name can contain any combination of lowercase letters (a-z), numbers (0-9), and hyphens (-).
    • Allowed Clusters: select a cluster for the tenant.
    • Admin Role: select one or more administrators for the tenant.

After you have created a tenant, continue on to creating a namespace for that tenant.

Create a namespace

  1. On the left navigation pane, under Tenant/Namespace, select the name of the tenant you just created in Step 5, and click New Namespace.

  2. On the Namespace page, click New Namespace.

  3. Enter a name for the namespace and then click Confirm. A namespace name can contain any combination of lowercase letters (a-z), numbers (0-9), and hyphens (-).

After you have created a namespace, contiune on to creating a topic.

Create a topic

It's recommended to have at least one partition per topic so that you can add more partitions in the future. If there are zero partitions (a non-partitioned topic), you will not be able add more partitions to the topic after it is created.

  1. On the left navigation pane, under Resources, click Topics.

  2. Click New Topic.

  3. Configure the topic and then click Confirm.

    • Domain: configure whether the topic is a persistent topic or a non-persistent topic.
    • Topic Name: enter a name for the topic. A topic name can contain any combination of lowercase letters (a-z), numbers (0-9), and hyphens (-).
    • Partitions: configure the number of partitions for a topic. You can have from 1 up to 100 partitions per topic. It's recommended to have at least 1 partition.

After you have created a topic, continue on to connecting to your cluster.

Connect to the cluster

This example shows how to connect to your cluster using the Pulsar Java client through the OAuth2 authentication plugin. For details about how to connect through other Pulsar CLI tools or clients, see connect.

  1. Get the service URL. For details about how to get service URLs, see get Pulsar service URLs.

  2. Get OAuth2 authentication parameters. For details about how to get OAuth2 authentication parameters, see get OAuth2 authentication parameters.

  3. Connect to the cluster through the OAuth2 authentication plugin.

    PulsarClient client = PulsarClient.builder()
    .serviceUrl("pulsar+ssl://streamnative.cloud:6651")
    .authentication(
       AuthenticationFactoryOAuth2.clientCredentials(this.issuerUrl, this.credentialsUrl, this.audience))
    .build();
    

    Set the serviceUrl parameter to the service URL that you obtained in Step 1. Get the issuer_url, audience, and credentialsUrl parameters to values that you obtained in Step 2.

  4. Create a Pulsar Java consumer to consume messages.

    Consumer<byte[]> consumer = client.newConsumer(Schema.BYTES)
           .topic(topic)
           .subscriptionName("sub-1")
           .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
           .subscribe();
    
    for (int i = 0; i < 10; i++) {
       Message<byte[]> msg = consumer.receive();
       consumer.acknowledge(msg);
       System.out.println("Receive message " + new String(msg.getData()));
    }
    
  5. Create a Pulsar Java producer to produce messages.

       PulsarClient client = PulsarClient.builder()
               .serviceUrl(jct.serviceUrl)
               .authentication(
                       AuthenticationFactoryOAuth2.clientCredentials(new URL(jct.issuerUrl), new URL(jct.credentialsUrl), jct.audience))
               .build();
    
       ProducerBuilder<byte[]> producerBuilder = client.newProducer().topic(topic)
               .producerName("my-producer-name");
       Producer<byte[]> producer = producerBuilder.create();
    
       for (int i = 0; i < 10; i++) {
           String message = "my-message-" + i;
           MessageId msgID = producer.send(message.getBytes());
           System.out.println("Publish " + "my-message-" + i + " and message ID " + msgID);
       }
    

Next steps

After you have successfully set up your StreamNative Cloud Console and connected to the cluster, you can learn more about working with StreamNative Cloud by reading through the Concepts topic or take a deep dive into Pulsar concepts on StreamNative Academy.

Previous
Cloud objects